Skip to main content

NullPointerException at java.util.EnumMap. after invoking JAXBContext

1 reply [Last post]
soutomaioel
Offline
Joined: 2008-07-15
Points: 0

Hi all,

I have spent like three weeks trying to figure out this problem.

I have an abstract generic class which takes a formal type parameter K that must extend Enum. This same class has a field of type K which is annotated with @XmlAttribute.

Furthermore, I have two different enum types of my own, which both are annotated with @XmlType and @XmlEnum with their respective @XmlEnumValue annotations for each constant. I want to be able to subclass the abstract generic class were substituting K with one of my enum types.

Now, the problem arises after invoking JAXBContext.newInstance(Class...).

I get a NullPointerException at java.util.EnumMap. without a message! I had it working once with the 2.0 implementation but not with the 2.1.

Here's part of the generic class definition:
/****************************************************************************************
@XmlAccessorType(XmlAccessType.NONE)
public abstract class Attribute> {

@XmlAttribute
protected K kind = null;
...
}

Here's part of the Enum class:
/***************************************************************************************
@XmlType
@XmlEnum
public enum ColumnKind {

@XmlEnumValue("date")
DATE {
},
...
}

Here's the stack trace:
/**************************************************************************************
java.lang.NullPointerException
at java.util.EnumMap.(Unknown Source)
at com.sun.xml.bind.v2.model.impl.RuntimeEnumLeafInfoImpl.(RuntimeEnumLeafInfoImpl.java:83)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createEnumLeafInfo(RuntimeModelBuilder.java:105)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createEnumLeafInfo(RuntimeModelBuilder.java:81)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:224)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:100)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:81)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:209)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:95)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:81)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:315)
at com.sun.xml.bind.v2.model.impl.SingleTypePropertyInfoImpl.getTarget(SingleTypePropertyInfoImpl.java:90)
at com.sun.xml.bind.v2.model.impl.RuntimeAttributePropertyInfoImpl.getTarget(RuntimeAttributePropertyInfoImpl.java:62)
at com.sun.xml.bind.v2.model.impl.RuntimeAttributePropertyInfoImpl.getTarget(RuntimeAttributePropertyInfoImpl.java:50)
at com.sun.xml.bind.v2.model.impl.SingleTypePropertyInfoImpl.ref(SingleTypePropertyInfoImpl.java:84)
at com.sun.xml.bind.v2.model.impl.RuntimeAttributePropertyInfoImpl.ref(RuntimeAttributePropertyInfoImpl.java:66)
at com.sun.xml.bind.v2.model.impl.RuntimeAttributePropertyInfoImpl.ref(RuntimeAttributePropertyInfoImpl.java:50)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:255)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:100)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:81)
at com.sun.xml.bind.v2.model.impl.ClassInfoImpl.getBaseClass(ClassInfoImpl.java:214)
at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl.getBaseClass(RuntimeClassInfoImpl.java:145)
at com.sun.xml.bind.v2.model.impl.RuntimeClassInfoImpl.getBaseClass(RuntimeClassInfoImpl.java:81)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:258)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:100)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:81)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:209)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:95)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:81)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:315)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:330)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:442)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:297)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:117)
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.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at edu.uprm.myapplication.Application.(Application.java:71)

I don't know what's wrong! Is it something wrong with my annotations?

Any help will be truly appreciated! Thanks very much!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nddipiazza
Offline
Joined: 2012-08-21
Points: 0

Also looking for a solution to this. Any work-arounds you found?