Skip to content
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

Closed
Tomas-Kraus opened this issue Sep 6, 2007 · 12 comments

Comments

@Tomas-Kraus
Copy link
Member

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]

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
Reported by colebatchd

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
Was assigned to snajper

@Tomas-Kraus
Copy link
Member Author

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

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
@pavelbucek said:
fixed in trunk

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
Marked as fixed on Wednesday, March 4th 2009, 12:51:27 am

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
snajper said:
Updated version, for some reason the fix was not merged from trunk.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
cfsavant said:
I have tried this with 2.2.5u2 and I still have the issue. Any suggestions?

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
snajper said:
Are you sure you're running with latest version? When running on JDK6 you need to make sure to setup endorsed properly.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
yaroska said:
Hi @coconnor,

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

Thanks.

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
coconnor said:
Hi Iaroslav,
I've done so as a new JIRA. It seemed appropriate. (#1052)

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

@Tomas-Kraus
Copy link
Member Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JAXB-415

@Tomas-Kraus
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants