[squeak-dev] OrderedCollection>>size fails in debugger
Ben Coman
btc at openInWorld.com
Mon Jul 11 03:51:59 UTC 2011
Levente Uzonyi wrote:
> On Mon, 11 Jul 2011, Ben Coman wrote:
>> I am writing some code that uses OrderedCollection and was tracing
>> through it with the debugger when the debugger itself threw a DNU
>> exception. I narrowed down reproduction of this to executing the
>> following line, clicking <Debug> then eight times <Into> :
>>> self halt. OrderedCollection new: 5.
>> As far as I can determine, the root cause is that
>> "OrderedCollectionInspector>>fieldList" calls "object size" which has
>> the following implementation:
>>> OrderedCollection>>size
>>> ^ lastIndex - firstIndex + 1
>> where "lastIndex" is nil (and also "firstIndex" is nil).
> Back in the caller, rather than:
>>> OrderedCollection>>fieldList
>>> object ifNil: [ ^ OrderedCollection new].
>>> ^ self baseFieldList ,
>>> (object size <= (self i1 + self i2) <snip>
>>
>>
>> this corrected the problem:
>>> OrderedCollection>>fieldList
>>> object ifNil: [ ^ OrderedCollection new].
>>> [ object size ] on: Exception do: [ ^ self baseFieldList ].
>>> ^ self baseFieldList ,
>>> (object size <= (self i1 + self i2) <snip>
> Yes, OrderedCollectionInspector should be changed, because that's what
> causes the problem. I'd simply create an #objectSize method for it and
> use that instead of object size.
> Levente
>> cheers, Ben
Do you not like leaving the line "[ object size ] on: Exception do: [ ^
self baseFieldList ]" where it is ?
Was your thought to create #objectSize in OrderedCollection or
OrderedCollectionInspector? At first I assumed you meant
OrderedCollection>>objectSize since OrderedCollectionInspector would
still not know whether lastIndex was nil, and would seem to require the
same exception handling. But perhaps you meant that
OrderCollectionInspector>>objectSize should just wrap the exception
handling, and so would be...
OrderCollectionInspector>>objectSize
[ object size ] on: Exception do: [ ^ 0 ].
^ object size.
OrderCollectionInspector>>fieldList
object ifNil: [ ^ OrderedCollection new].
^ self baseFieldList ,
(self objectSize <= (self i1 + self i2)
ifTrue: [(1 to: self objectSize)
collect: [:i | i printString]]
ifFalse: [(1 to: self i1) , (self objectSize - (self i2-1)
to: self objectSize)
collect: [:i | i printString]])
Although I wonder if a cleaner implementation that exception handling
could be...
OrderCollection>>hasSize
lastIndex ifNil: [ ^false ].
firstIndex ifNil: [ ^false ].
^true.
OrderCollectionInspector>>objectSize
object hasSize ifTrue: [^ object size ] ifFalse: [ ^0 ].
More information about the Squeak-dev
mailing list
|