Details
-
Type: Bug
-
Status: Closed
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
JDK version and platform:1.4.2 for OS X
Description
The following three classes together illustrate a null pointer exception during deserialization.
Comments
---------
The error occurs when attempting to get the hashcode of SuperA. The variable "uid" is null. It appears that the super is not fully deserialized before the request by the set for the hashcode.
Deserialization works fine if the super class is removed - and uid and overridden hashcode are moved to "A". Additionally, (perhaps obviously) deserialization works fine if the LinkedHashSet is changed to a collection that does not request the identifier, e.g. ArrayList.
Test Output
----------
<A>
<parent>
<parent reference="../.."/>
<children>
<A reference="../../.."/>
</children>
<uid>2</uid>
</parent>
<children>
<A reference="../../parent"/>
</children>
<uid>1</uid>
</A>
com.thoughtworks.xstream.converters.ConversionException: null
---- Debugging information ----
required-type : java.util.HashSet
cause-message : null
class : A
line number : 5
path : /A/parent/children/A
cause-exception : java.lang.NullPointerException
-------------------------------
<-- Stack Trace Excluded-->
Test Classes
----------
import com.thoughtworks.xstream.XStream;
public class XStreamTest {
public static void main(String[] args) {
try
catch (Throwable t)
{ System.err.println(t); } }
}
public class SuperA {
private Integer uid = null;
public SuperA(Integer uid)
{ this.uid = uid; }public int hashCode()
{ return uid.hashCode(); }}
import java.util.HashSet;
import java.util.Set;
public class A extends SuperA {
private A parent = null;
private Set children = new HashSet();
public A(Integer uid)
{ super(uid); }public void addChild(A child)
{ children.add(child); child.setParent(this); }public void setParent(A parent)
{ this.parent = parent; }}
Linking duplicates.