XStream
  1. XStream
  2. XSTR-425

NPE thrown when @XStreamImplicit is used on collection with interface parameter type

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Upcoming
    • Fix Version/s: 1.3
    • Component/s: Annotations
    • Labels:
      None
    • JDK version and platform:
      Sun 1.6.0_02 for Windows

      Description

      There is a bug (version: 1.3.0-SNAPSHOT Sep 4, 2007) that prevents one from using the @XStreamImplicit annotation on elements that have an interface type as the parameter type. Here is an example that shows the bug:

      @XStreamImplicit()
      private ArrayList<Map> list = new ArrayList<Map>(); // Notice the parameter type is an interface (Map).

      It will work when written like so:

      @XStreamImplicit()
      private ArrayList<HashMap> list = new ArrayList<HashMap>(); // Notice the parameter type is not an interface (HashMap).

      I have tracked the bug down to the if statement on line 233 in com.thoughtworks.xstream.annotations.Annotations.
      It checks if the parameterized type is an interface, and if so, it assumes it has an XStreamAlias (seems odd to begin with) annotation and tries to retrieve it (line 235). If the interface does not have an XStreamAlias annotation, the getAnnotation() method returns null, and the statement on line 237 will fail because it tries to invoke the impl() method on a null reference.

      Try the attached code for yourself.

      Thanks,

      Paul van der Maas

      P.S. I may write a patch myself, once I figure out how to work with NetBeans/SubVersion/Maven . Any help on that would be appreciated to.

      1. Main.java
        0.4 kB
        Paul van der Maas
      2. XStreamTest.java
        0.3 kB
        Paul van der Maas

        Issue Links

          People

          • Assignee:
            Jörg Schaible
            Reporter:
            Paul van der Maas
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: