[
https://issues.apache.org/jira/browse/COLLECTIONS-266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12527413
]
Joerg Schaible commented on COLLECTIONS-266:
--------------------------------------------
Well, this problem with Enums has a history:
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6421053
- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6373406
However, in the end you're right and the hashCode should not have been stored
in the MultiKey in this way. We might solve this by adding a readResolve method:
private Object readResolve() {
return new MultiKey(keys, false);
}
that way we create a new MultiKey with the correct hashCode. Your solution with
the transient member will break the serialization compatibility, since you
changed the binary layout. Therefore the hashCode member *must* be serialized -
otherwise you have to change also the serialVersionUID. But with a private
calculateHashCode method and setting the hashCode member not to final, we can
implement readResolve different:
private Object readResolve() {
calculateHashCode();
return this;
}
But our clirr report may still choke about the final.
- Jörg
> 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.