axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Gregg" <>
Subject [PATCH] RE: Is this a bug in serialization?
Date Wed, 03 Jul 2002 18:29:00 GMT
Here's fix to the serialization problem Naresh had.

To summarize the problem, in cases where two distinct objects for which
equals() returned true and hashCode() returned the same value, only one
"instance" would appear in the serialized output.  The correct result was
for 2 instances to appear in the output (2 objects in, 2 objects out.)

The cause was the reliance on the instances' equals() and hashCode()
methods.  If SerializationContextImpl.doMultiRefs == true, then serialized
objects were cached in a HashMap keyed by the object itself.  With that
particular caching mechanism, objects that were equal but not identical were
incorrectly treated as the same object.  The fix was simply to key the map
by System.identityHashCode(o).

The test class I'm providing here exposes the problem in testEquality3().

Another random thought:

Someone added a secondLevelObjects instance variable to
SerializationContextImpl and populates it under certain conditions but never
uses it otherwise.  It looks like someone just got sidetracked and didn't
finish his thought.


-----Original Message-----
Behalf Of John Gregg
Sent: Wednesday, July 03, 2002 9:26 AM
Subject: RE: Is this a bug in serialization?

I'm working on a fix right now.  I think fixing it is easy-- writing the
test is a little more work.


View raw message