Reputation: 275
I'm having a serious issue while trying to unmarshal an XML. At first, the Member elements contained only Integer in their "value" attributes (like the first 'EnumType' element), however, now that another 'EnumType' appears with Strings as the value - I'm getting the bellow NullPointerException.
Notice, that the 'value' member in Member.java was from type "int" at the beginning (when only Integer was accepted as values of the Member element) and it worked fine. Only when I have changed it to Object (and I guess this is the source of my issue) - the below exception was appeared.
XML:
<EnumType Name="Genre" UnderlyingType="Edm.Int32">
<Member Name="ACTION" Value="0"/>
<Member Name="COMEDY" Value="1"/>
</EnumType>
<EnumType Name="Rating" UnderlyingType="Edm.String">
<Member Name="RatingA" Value="G"/>
<Member Name="RatingB" Value="PG"/>
</EnumType>
EnumType.java
@XmlRootElement
public class EnumType {
@XmlElement(name = "Member", namespace = "http://schemas.microsoft.com/ado/2009/11/edm")
private List<Member> members = new LinkedList<Member>();
public List<Member> getMembers() {
return members;
}
}
Member.Java
@XmlRootElement
public class Member {
@XmlAttribute(name = "Name")
private String name;
@XmlAttribute(name = "Value")
private Object value;
public String getName() {
return name;
}
public Object getValue() {
return value;
}
}
When unmarshaling the above XML I'm getting this NullPointerException:
java.lang.NullPointerException at com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor.get(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.(Unknown Source) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source) at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at javax.xml.bind.ContextFinder.newInstance(Unknown Source) at javax.xml.bind.ContextFinder.newInstance(Unknown Source) at javax.xml.bind.ContextFinder.find(Unknown Source) at javax.xml.bind.JAXBContext.newInstance(Unknown Source) at javax.xml.bind.JAXBContext.newInstance(Unknown Source) at com.sap.ndb.studio.rdl.csdlparser.jaxb.JAXBParser.load(JAXBParser.java:26) at com.sap.ndb.studio.rdl.datapreview.functions.LoadGRDL.function(LoadGRDL.java:59) at org.eclipse.swt.browser.WebSite.Invoke(WebSite.java:773) at org.eclipse.swt.browser.WebSite$7.method6(WebSite.java:129) at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:119) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2546) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3756) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499) at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584) at org.eclipse.equinox.launcher.Main.run(Main.java:1438) at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Any ideas? :(
Upvotes: 2
Views: 4162
Reputation: 148987
The JAXB RI will throw that exception when you annotate a field/property of type Object with @XmlAttribute
. Like you have in your Member
class:
@XmlAttribute(name = "Value")
private Object value;
For More Information
Upvotes: 5