XStream
  1. XStream
  2. XSTR-407

Comparing uninitialized objects

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.3
    • Component/s: Converters, Core
    • Labels:
      None
    • JDK version and platform:
      Sun 1.5.0_11 for Windows

      Description

      Below is the minimal case for the problem I came across. During deserialization NPE is thrown from compareTo method, probably because object is put in the tree before id is filled. Simple workaround is to change the order of the fields, but sometimes it's not possible (for example when field is inherited).

      import java.util.Set;
      import java.util.TreeSet;
      import junit.framework.TestCase;
      import com.thoughtworks.xstream.XStream;

      public class Test extends TestCase {
      XStream xs = new XStream();

      public void test()

      { C c = new C(1); c.others.add(c); c.others.add(new C(2)); xs.fromXML(xs.toXML(c)); }

      }

      class C implements Comparable {
      Set<C> others = new TreeSet<C>();
      final Integer id;

      C(Integer id)

      { this.id = id; }

      public int compareTo(Object o)

      { return id.compareTo(((C) o).id); }

      }

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          jsmyczek
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: