New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Marshaller.marshall throws NPE if an adapter adapts a non-null bound value to null. #415
Comments
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented can you please provide small testCase. So we'll be able to reproduce the problem ? Thanks. |
@glassfishrobot Commented (Once I figured out how to re-login - the java.net JIRA is very broken, you have to logout and then login again!!!) |
@glassfishrobot Commented |
|
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)
Environment
Operating System: All
Platform: All
Affected Versions
[2.1.4]
The text was updated successfully, but these errors were encountered: