Bug in exception handling

Ralph Johnson johnson at cs.uiuc.edu
Mon Jun 17 22:36:39 UTC 2002


I discovered the following Squeak bug last week at Camp Smalltalk.

The bug occurs when you have a doubly-nested ensure:.  If the inner ensure:
has two errors, one in both the first block and the second, the system does
not handle it correctly.  In particular, the exception handler that is
supposed to handle those errors gets by-passed.  The bug does not occur if
you only have a single-nested ensure:.

I wrote a couple of test cases to illustrate this bug.  One of them
generates an error that is properly handled by SUnit.  The other generates
an error notification.  Since SUnit is supposed to capture all errors, this
is a bug.


-Ralph Johnson

-------------- next part --------------
TestCase subclass: #JohnsonExceptionBugTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'ExceptionBug'!

!JohnsonExceptionBugTest methodsFor: 'testing' stamp: 'rej 6/15/2002 17:50'!
testDoubllyNestedEnsure
	"note that SUnit already wraps test cases in one ensure.  So, this is the second.
	The bug happens when the first block fails and then the second block fails, too."
	| fileStream |
	[fileStream _ FileStream openFileNamed: 'TheMethodNameIsWrongSoThisFails']
		ensure: 
		[fileStream close]
	"fileStream is nil, so the second block fails, too"! !


TestCase subclass: #JohnsonExceptionBugTest2
	instanceVariableNames: 'fileStream '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'ExceptionBug'!

!JohnsonExceptionBugTest2 methodsFor: 'as yet unclassified' stamp: 'rej 6/15/2002 17:54'!
setUp
	fileStream := FileStream claimToOpenFile: 'myfile'! !

!JohnsonExceptionBugTest2 methodsFor: 'as yet unclassified' stamp: 'rej 6/15/2002 17:54'!
tearDown
	fileStream close! !

!JohnsonExceptionBugTest2 methodsFor: 'as yet unclassified' stamp: 'rej 6/15/2002 19:42'!
testExceptionBug
	"This test does nothing to show that if you don't nest ensures, SUnit can handle failures in both blocks.
	setUp will fail and so will tearDown.  It only reports setUp, but at least it doesn't popup a notifier"! !


More information about the Squeak-dev mailing list