Index: src/java/org/apache/commons/collections/keyvalue/MultiKey.java =================================================================== --- src/java/org/apache/commons/collections/keyvalue/MultiKey.java (revision 575016) +++ src/java/org/apache/commons/collections/keyvalue/MultiKey.java (working copy) @@ -17,6 +17,8 @@ package org.apache.commons.collections.keyvalue; import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; import java.util.Arrays; /** @@ -54,7 +56,7 @@ /** The individual keys */ private final Object[] keys; /** The cached hashCode */ - private final int hashCode; + private transient int hashCode; /** * Constructor taking two keys. @@ -164,13 +166,7 @@ this.keys = keys; } - int total = 0; - for (int i = 0; i < keys.length; i++) { - if (keys[i] != null) { - total ^= keys[i].hashCode(); - } - } - hashCode = total; + calculateHashCode(); } //----------------------------------------------------------------------- @@ -255,4 +251,29 @@ return "MultiKey" + Arrays.asList(keys).toString(); } + /** + * Calculate the cached hash code. + */ + private void calculateHashCode() { + int total = 0; + for (int i = 0; i < keys.length; i++) { + if (keys[i] != null) { + total ^= keys[i].hashCode(); + } + } + hashCode = total; + } + + /** + * Recalculate the cached hashcode each time the multikey is deserialized. + * + * @param in + * @throws IOException + * @throws ClassNotFoundException + */ + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + calculateHashCode(); + } + }