[Pharo-project] Problem with PluggableListMorph
There are cases when PluggableListMorph has is inner list cache in nil: *getListElementSelector: aSymbol "specify a selector that can be used to obtain a single element in the underlying list" getListElementSelector := aSymbol. list := nil. "this cache will not be updated if getListElementSelector has been specified, so go ahead and remove it"* ... But, there are some methods that send messages to that nil list and blow up :D, such as: *backgroundColorFor: aRow | anItem return | aRow ifNil: [ ^nil ]. anItem := list at: aRow ifAbsent: [ ^ nil ]. ... * Now, two solutions comes to my mind: put one more ward in: *backgroundColorFor: aRow | anItem return | (aRow isNil or: [ list isNil ]) ifTrue: [ ^nil ]. anItem := list at: aRow ifAbsent: [ ^ nil ]. ... * Or use #getList, which seems to be the most... cleaner. *backgroundColorFor: aRow | anItem return | aRow ifNil: [ ^nil ]. anItem := self getList at: aRow ifAbsent: [ ^ nil ]. ... * ? Guille, (meanwhile, opening a ticket :)).
http://code.google.com/p/pharo/issues/detail?id=5183&thanks=5183&ts=13267335... On Mon, Jan 16, 2012 at 2:05 PM, Guillermo Polito <guillermopolito@gmail.com
wrote:
There are cases when PluggableListMorph has is inner list cache in nil:
*getListElementSelector: aSymbol "specify a selector that can be used to obtain a single element in the underlying list" getListElementSelector := aSymbol. list := nil. "this cache will not be updated if getListElementSelector has been specified, so go ahead and remove it"* ...
But, there are some methods that send messages to that nil list and blow up :D, such as:
*backgroundColorFor: aRow
| anItem return | aRow ifNil: [ ^nil ]. anItem := list at: aRow ifAbsent: [ ^ nil ]. ... * Now, two solutions comes to my mind:
put one more ward in:
*backgroundColorFor: aRow
| anItem return | (aRow isNil or: [ list isNil ]) ifTrue: [ ^nil ]. anItem := list at: aRow ifAbsent: [ ^ nil ]. ... * Or use #getList, which seems to be the most... cleaner.
*backgroundColorFor: aRow
| anItem return | aRow ifNil: [ ^nil ]. anItem := self getList at: aRow ifAbsent: [ ^ nil ]. ... * ?
Guille, (meanwhile, opening a ticket :)).
participants (1)
-
Guillermo Polito