commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COLLECTIONS-266) Issue with MultiKey when serialized/deserialized via RMI
Date Wed, 12 Sep 2007 23:44:32 GMT

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

Henri Yandell commented on COLLECTIONS-266:
-------------------------------------------

While creating the test I realized that the use case that found this problem seems quite rare.

* MultiKey goes into Map. 
* Map gets sent through serialize/deserialize. 
* We have a new map, with a new multikey inside, with a new object inside that, and the multikey
has based its hashCode on the old address of the object and not the new one.

If you dig that object out of the map, and then use it to try and get itself back out of the
map; then you've got a problem. So definitely a bug of sorts.

But how did you get access to the object in the first place? :)

In my unit test, I transfer the Map, then have to get the key back out of the map to then
use in a get request. ie:

        MultiKey mk2 = (MultiKey) map2.keySet().iterator().next();
        assertEquals(TWO, map2.get(mk2));

I find that the test passes for both the old code and your new code. Any idea what I'm doing
differently?

> 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
>         Attachments: COLLECTIONS-266.patch, MultiKey.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.


Mime
View raw message