You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2002/08/31 13:27:34 UTC
cvs commit: xml-axis/java/test/encoding TestMultiRefIdentity.java
scheu 2002/08/31 04:27:33
Modified: java/src/org/apache/axis/encoding
SerializationContextImpl.java
java/test/encoding TestMultiRefIdentity.java
Log:
Fix for Bugzilla bugs http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11706
and http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11706
The problem is the multiRefValues HashMap in
SerializationContextImpl. The key to the map was
recently fixed to be the identityHashCode of the
Object value. However this fix is not sufficient because
the Java environment does not guarantee that this
hash code uniquely identifes objects (it normally does
but there is no guarantee).
The solution is to add an IDKey object that contains
the identity hashCode and a reference to the value. The
IDKey hashCode() method returns the identity hashCode and
the equals() method compares the identity hashCode AND
does an identity equals on the values.
The performance is probably better because we were
generating Strings for the keys.
Bingo
Revision Changes Path
1.63 +41 -7 xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java
Index: SerializationContextImpl.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- SerializationContextImpl.java 27 Aug 2002 16:08:09 -0000 1.62
+++ SerializationContextImpl.java 31 Aug 2002 11:27:33 -0000 1.63
@@ -753,16 +753,42 @@
}
/**
- * Get a String representation of the identity hashCode for a given
- * Object. This can be used as a unique key into a HashMap which will
+ * Get an IDKey that represents the unique identity of the object.
+ * This is used as a unique key into a HashMap which will
* not give false hits on other Objects where hashCode() and equals()
* have been overriden to match.
*
* @param value the Object to hash
- * @return a String containing the unique identity hashCode
+ * @return a unique IDKey for the identity
*/
- private String getIdentityKey(Object value) {
- return "" + System.identityHashCode(value);
+ private IDKey getIdentityKey(Object value) {
+ return new IDKey(value);
+ }
+ class IDKey {
+ private Object value = null;
+ private int id = 0;
+ public IDKey(Object _value) {
+ // This is the Object hashcode
+ id = System.identityHashCode(_value);
+ // There have been some cases (bug 11706) that return the
+ // same identity hash code for different objects. So
+ // the value is also added to disambiguate these cases.
+ value = _value;
+ }
+ public int hashCode() {
+ return id;
+ }
+ public boolean equals(Object other) {
+ if (!(other instanceof IDKey)) {
+ return false;
+ }
+ IDKey idKey = (IDKey) other;
+ if (id != idKey.id) {
+ return false;
+ }
+ // Note that identity equals is used.
+ return value == idKey.value;
+ }
}
/**
@@ -802,8 +828,11 @@
"CDATA",
encodingStyle);
- Iterator i =
- ((HashMap)multiRefValues.clone()).keySet().iterator();
+ // Make a copy of the keySet because it could be updated
+ // during processing
+ HashSet keys = new HashSet();
+ keys.addAll(multiRefValues.keySet());
+ Iterator i = keys.iterator();
while (i.hasNext()) {
while (i.hasNext()) {
Object val = i.next();
@@ -832,8 +861,13 @@
secondLevelObjects = null;
}
}
+
+ // Reset maps and flags
forceSer = null;
outputMultiRefsFlag = false;
+ multiRefValues = null;
+ multiRefIndex = -1;
+ secondLevelObjects = null;
}
/**
1.3 +12 -12 xml-axis/java/test/encoding/TestMultiRefIdentity.java
Index: TestMultiRefIdentity.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/encoding/TestMultiRefIdentity.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestMultiRefIdentity.java 22 Jul 2002 20:10:05 -0000 1.2
+++ TestMultiRefIdentity.java 31 Aug 2002 11:27:33 -0000 1.3
@@ -117,8 +117,8 @@
// Cheap but fragile.
int first = s.indexOf("#id0");
int last = s.lastIndexOf("#id0");
- assertTrue(first >= 0);
- assertTrue(last >= 0 && last != first);
+ assertTrue(s, first >= 0);
+ assertTrue(s, last >= 0 && last != first);
}
/**
@@ -140,8 +140,8 @@
// Cheap but fragile.
int first = s.indexOf("#id0");
int last = s.lastIndexOf("#id0");
- assertTrue(first >= 0);
- assertTrue(last >= 0 && last != first);
+ assertTrue(s,first >= 0);
+ assertTrue(s,last >= 0 && last != first);
}
/**
@@ -164,8 +164,8 @@
// Cheap but fragile.
int first = s.indexOf("#id0");
int last = s.lastIndexOf("#id1");
- assertTrue(first >= 0);
- assertTrue(last >= 0);
+ assertTrue(s,first >= 0);
+ assertTrue(s,last >= 0);
}
/**
@@ -188,8 +188,8 @@
// Cheap but fragile.
int first = s.indexOf("#id0");
int last = s.lastIndexOf("#id1");
- assertTrue(first >= 0);
- assertTrue(last >= 0);
+ assertTrue(s,first >= 0);
+ assertTrue(s,last >= 0);
}
/**
@@ -212,8 +212,8 @@
// Cheap but fragile.
int first = s.indexOf("#id0");
int last = s.lastIndexOf("#id1");
- assertTrue(first >= 0);
- assertTrue(last >= 0 && last != first);
+ assertTrue(s,first >= 0);
+ assertTrue(s,last >= 0 && last != first);
}
class TestBeanA {