XStream
  1. XStream
  2. XSTR-184

Issue regarding circular references, sets, and superclass

    Details

    • Type: Bug Bug
    • Status: Closed 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

      { final XStream xstream = new XStream(); final A parent = new A(new Integer(1)); final A child = new A(new Integer(2)); parent.addChild(child); child.addChild(parent); String serialized = xstream.toXML(parent); System.out.println(serialized); xstream.fromXML(serialized); System.out.println("Success"); }

      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; }

      }

        Issue Links

          People

          • Assignee:
            Unassigned
            Reporter:
            Ron Lancaster
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: