Bug 44961

GemStone/S 64 Bit

3.2.6, 3.2.5, 3.2.4, 3.2.3, 3.2.2, 3.2.1, 3.2, 3.1.0.6, 3.1.0.5, 3.1.0.4, 3.1.0.2, 3.0.1, 3.0, 2.4.8, 2.4.7, 2.4.6, 2.4.5.1, 2.4.5, 2.4.4.8, 2.4.4.7, 2.3.1.6, 2.2.5.4

All Platforms

3.2.7

RcKeyValueDictionary at:ifAbsent and at:otherwise: returns an error on a nil key

The following two methods return the error #rtErrNilKey (error 2090) when the specified key is nil.  Since these methods are intended to provide alternate handling of nil keys, this is incorrect behavior.

    #at:ifAbsent:
    #at:otherwise:

Workaround

As SystemUser file-in and commit the following code.

category: 'Accessing'
method: RcKeyValueDictionary
at: aKey ifAbsent: aBlock

"Returns the value that corresponds to aKey.  If no such key/value pair exists,
 returns the result of evaluating the zero-argument block aBlock."

| hash |
aKey == nil ifTrue: [ ^ aBlock value ].

hash := self hashFunction: aKey.
^ (self _at: hash) at: aKey ifAbsent: aBlock
%

category: 'Accessing'
method: RcKeyValueDictionary
at: aKey otherwise: aValue

"Returns the value that corresponds to aKey.  If no such key/value pair exists,
 returns the given alternate value."

| hash |
aKey == nil ifTrue: [ ^ value ].

hash := self hashFunction: aKey.
^ (self _at: hash) at: aKey otherwise: aValue
%

Last updated: 1/23/15