[ 
https://issues.apache.org/jira/browse/COLLECTIONS-266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12527365
 ] 

Joerg Schaible commented on COLLECTIONS-266:
--------------------------------------------

IMHO the key simply violates the contract. Extract from Javadoc to 
Object.hashCode:

- If two objects are equal according to the equals(Object)  method, then 
calling the hashCode method on each of the two objects must produce the same 
integer result

It also states:

- Whenever it is invoked on the same object more than once during an execution 
of a Java application, the hashCode method must consistently return the same 
integer, provided no information used in equals comparisons on the object is 
modified. This integer need not remain consistent from one execution of an 
application to another execution of the same application.

Without testing it, but if you use this key not as part of a MultiKey, but of a 
HashMap directly, you might get the same results.

> Issue with MultiKey when serialized/deserialized via RMI
> --------------------------------------------------------
>
>                 Key: COLLECTIONS-266
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-266
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: KeyValue
>    Affects Versions: 3.2
>            Reporter: Julien Buret
>            Priority: Minor
>             Fix For: 3.3
>
>         Attachments: COLLECTIONS-266.patch, MultiKey.java, 
> TestCollections266.java, TestCollections266.java, TestCollections266.java
>
>
> This is because the hash code of MultiKey is calculated only once. 
> So if the MultiKey is deserialized in an other jvm, and if one at least of 
> the subkeys defines its hash code with System.identityHashCode() (for example 
> all the enums does), then the hash code of the MultiKey is no longer valid, 
> and you can't retreive the key in your Map.
> I fixed it by making the cached hash code field transient, and by 
> recalculating the hash code during deserialization. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to