XStream
  1. XStream
  2. XSTR-338

NPE in JsonHierarchicalStreamWriter.startNode(Class clazz) when clazz is null

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.1
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
      Sun 1.5.0_06 for Windows

      Description

      Tried the experimental JSON support and ran into a NPE when ColorConverter attempts to marshall a Color.class instance as four ints, calling startNode(String) without the 2nd Class parameter:

      Exception in thread "main" java.lang.NullPointerException
      at java.lang.Class.isAssignableFrom(Native Method)
      at com.thoughtworks.xstream.io.json.JsonHierarchicalStreamWriter.startNode(JsonHierarchicalStreamWriter.java:77)
      at com.thoughtworks.xstream.io.json.JsonHierarchicalStreamWriter.startNode(JsonHierarchicalStreamWriter.java:58)
      at com.thoughtworks.xstream.io.WriterWrapper.startNode(WriterWrapper.java:17)
      at com.thoughtworks.xstream.io.path.PathTrackingWriter.startNode(PathTrackingWriter.java:25)
      at com.thoughtworks.xstream.converters.extended.ColorConverter.write(ColorConverter.java:49)
      at com.thoughtworks.xstream.converters.extended.ColorConverter.marshal(ColorConverter.java:29)
      at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:59)
      at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
      at com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.marshallField(AnnotationReflectionConverter.java:37)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:105)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:81)
      at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:109)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:66)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:41)
      at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:59)
      at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:50)
      at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:73)
      at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.marshal(ReferenceByXPathMarshallingStrategy.java:34)
      at com.thoughtworks.xstream.XStream.marshal(XStream.java:745)
      at com.thoughtworks.xstream.XStream.marshal(XStream.java:734)
      at com.thoughtworks.xstream.XStream.toXML(XStream.java:715)
      at com.thoughtworks.xstream.XStream.toXML(XStream.java:705)
      ...

      1. json_writer_no_npe.patch
        1 kB
        Chris Winters
      2. XSTR338Test.java
        0.5 kB
        Chris Ingham

        Activity

        Hide
        Chris Ingham added a comment -

        JUnit test case

        Show
        Chris Ingham added a comment - JUnit test case
        Hide
        Chris Winters added a comment -

        Ensure a class is not null before checking if it's assignable from another class or it's an array.

        Show
        Chris Winters added a comment - Ensure a class is not null before checking if it's assignable from another class or it's an array.
        Hide
        Jörg Schaible added a comment -

        Patch Applied. Thanks!

        Show
        Jörg Schaible added a comment - Patch Applied. Thanks!
        Hide
        Jörg Schaible added a comment -

        Closed as fixed for 1.2.1

        Show
        Jörg Schaible added a comment - Closed as fixed for 1.2.1

          People

          • Assignee:
            Unassigned
            Reporter:
            Chris Ingham
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: