jaxb
  1. jaxb
  2. JAXB-415

Marshaller.marshall throws NPE if an adapter adapts a non-null bound value to null.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1.4
    • Fix Version/s: 2.2.4u2, 2.2.5
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      415

      Description

      The following source code demonstrates the problem:

      @XmlRootElement
      @XmlAccessorType(XmlAccessType.FIELD)
      public class Bar
      {
      @XmlElement
      @XmlJavaTypeAdapter(TestAdapter.class)
      private String v;

      public Bar()
      {
      }

      public Bar(String v)

      { this.v = v; }

      public static void main(String[] args) throws Exception

      { Marshaller m = JAXBContext.newInstance(Bar.class).createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(new Bar("foo"), System.out); }

      }

      import javax.xml.bind.annotation.adapters.XmlAdapter;

      public class TestAdapter extends XmlAdapter<String,String>
      {
      public String unmarshal(String v) throws Exception

      { return null; }

      public String marshal(String v) throws Exception
      { return null; }

      }

      Running Bar will give the following:

      Exception in thread "main" java.lang.NullPointerException
      at com.sun.xml.bind.v2.runtime.output.Encoded.setEscape
      (Encoded.java:107)
      at com.sun.xml.bind.v2.runtime.output.UTF8XmlOutput.doText
      (UTF8XmlOutput.java:305)
      at com.sun.xml.bind.v2.runtime.output.UTF8XmlOutput.text
      (UTF8XmlOutput.java:294)
      at com.sun.xml.bind.v2.runtime.output.IndentingUTF8XmlOutput.text
      (IndentingUTF8XmlOutput.java:152)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.leafElement
      (XMLSerializer.java:319)
      at
      com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafElement
      (RuntimeBuiltinLeafInfoImpl.java:209)
      at
      com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafElement
      (RuntimeBuiltinLeafInfoImpl.java:208)
      at
      com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccess
      orImpl.writeLeafElement(TransducedAccessor.java:250)
      at
      com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody
      (SingleElementLeafProperty.java:98)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody
      (ClassBeanInfoImpl.java:322)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent
      (XMLSerializer.java:587)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot
      (ClassBeanInfoImpl.java:312)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot
      (XMLSerializer.java:488)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write
      (MarshallerImpl.java:317)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal
      (MarshallerImpl.java:246)
      at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal
      (AbstractMarshallerImpl.java:75)
      at com.toyota.dim.jaxb.npetest.Bar.main(Bar.java:32)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke
      (NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke
      (DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

      I believe that the following is also caused by the same problem:

      Exception in thread "main" java.lang.NullPointerException
      at com.sun.xml.bind.v2.runtime.output.SAXOutput.text(SAXOutput.java:114)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.leafElement
      (XMLSerializer.java:303)
      at
      com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafElement
      (RuntimeBuiltinLeafInfoImpl.java:172)
      at
      com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafElement
      (RuntimeBuiltinLeafInfoImpl.java:171)
      at
      com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccess
      orImpl.writeLeafElement(TransducedAccessor.java:214)
      at
      com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody
      (SingleElementLeafProperty.java:62)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody
      (ClassBeanInfoImpl.java:286)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody
      (ClassBeanInfoImpl.java:283)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody
      (ClassBeanInfoImpl.java:283)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType
      (XMLSerializer.java:663)
      at
      com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem
      (ArrayElementNodeProperty.java:29)
      at
      com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody
      (ArrayElementProperty.java:132)
      at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody
      (ArrayERProperty.java:101)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody
      (ClassBeanInfoImpl.java:286)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent
      (XMLSerializer.java:571)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot
      (ClassBeanInfoImpl.java:276)
      at
      com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBod
      y(ArrayReferenceNodeProperty.java:78)
      at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody
      (ArrayERProperty.java:101)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody
      (ClassBeanInfoImpl.java:286)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType
      (XMLSerializer.java:663)
      at
      com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody
      (SingleElementNodeProperty.java:113)
      at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody
      (ClassBeanInfoImpl.java:286)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType
      (XMLSerializer.java:663)
      at
      com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody
      (SingleElementNodeProperty.java:113)
      at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody
      (ElementBeanInfoImpl.java:120)
      at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody
      (ElementBeanInfoImpl.java:149)
      at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody
      (ElementBeanInfoImpl.java:269)
      at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot
      (ElementBeanInfoImpl.java:276)
      at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot
      (ElementBeanInfoImpl.java:35)
      at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot
      (XMLSerializer.java:472)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.write
      (MarshallerImpl.java:301)
      at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal
      (MarshallerImpl.java:230)
      at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal
      (AbstractMarshallerImpl.java:96)
      at com.toyota.ibus.common.ws.SOAPMessage.stringify(SOAPMessage.java:560)
      at com.toyota.ibus.common.ws.SOAPMessage12.stringify
      (SOAPMessage12.java:81)
      at com.toyota.ibus.common.ws.WebServiceInvoker.invoke
      (WebServiceInvoker.java:124)
      at com.toyota.ibus.common.ws.WebServiceInvoker.invoke
      (WebServiceInvoker.java:91)
      at com.toyota.ibus.common.ws.WebServiceInvoker.invoke
      (WebServiceInvoker.java:70)
      at au.com.toyota.taipan.supplier.orders.ws.Scratch.send(Scratch.java:102)
      at au.com.toyota.taipan.supplier.orders.ws.Scratch.testDatabaseOrders
      (Scratch.java:128)
      at au.com.toyota.taipan.supplier.orders.ws.Scratch.main(Scratch.java:50)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke
      (NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke
      (DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

        Activity

        Hide
        kohsuke added a comment -

        Yeah, the null detection logic isn't taking the adapter into account, so this
        needs to involve a bit bigger change in the runtime.

        Show
        kohsuke added a comment - Yeah, the null detection logic isn't taking the adapter into account, so this needs to involve a bit bigger change in the runtime.
        Hide
        Pavel Bucek added a comment -

        fixed in trunk

        Show
        Pavel Bucek added a comment - fixed in trunk
        Hide
        Martin Grebac added a comment -

        Updated version, for some reason the fix was not merged from trunk.

        Show
        Martin Grebac added a comment - Updated version, for some reason the fix was not merged from trunk.
        Hide
        cfsavant added a comment -

        I have tried this with 2.2.5u2 and I still have the issue. Any suggestions?

        Show
        cfsavant added a comment - I have tried this with 2.2.5u2 and I still have the issue. Any suggestions?
        Hide
        Martin Grebac added a comment -

        Are you sure you're running with latest version? When running on JDK6 you need to make sure to setup endorsed properly.

        Show
        Martin Grebac added a comment - Are you sure you're running with latest version? When running on JDK6 you need to make sure to setup endorsed properly.
        Hide
        Iaroslav Savytskyi added a comment -

        Hi @coconnor,

        can you please provide small testCase. So we'll be able to reproduce the problem ?

        Thanks.

        Show
        Iaroslav Savytskyi added a comment - Hi @coconnor, can you please provide small testCase. So we'll be able to reproduce the problem ? Thanks.
        Hide
        coconnor added a comment -

        Hi Iaroslav,
        I've done so as a new JIRA. It seemed appropriate. (JAXB-1052)

        (Once I figured out how to re-login - the java.net JIRA is very broken, you have to logout and then login again!!!)

        Show
        coconnor added a comment - Hi Iaroslav, I've done so as a new JIRA. It seemed appropriate. ( JAXB-1052 ) (Once I figured out how to re-login - the java.net JIRA is very broken, you have to logout and then login again!!!)

          People

          • Assignee:
            Martin Grebac
            Reporter:
            colebatchd
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: