[JAXB-615] JAXBContext.newInstance fails with NPE if class has an Enum Created: 19/Mar/09  Updated: 21/Nov/12

Status: Open
Project: jaxb
Component/s: runtime
Affects Version/s: 2.1.8
Fix Version/s: not determined

Type: Bug Priority: Minor
Reporter: skells Assignee: Iaroslav Savytskyi
Resolution: Unresolved Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Attachments: Java Source File Issue.java    
Issuezilla Id: 615

 Description   

if a class to be bound has a Enum then jaxb seems to assume that it is an enum
(ie a specific type) and fails to bind. The exception produced is not helpful
to diagnose the problem. ALso occurs when using generics and the erased type is
Enum (this is how I found it)

This was checked against 2.1.10 and 2.1.8 (2.1.10 in not in the bug version
list)

stack trace from 2.1.10 for the test code is

Exception in thread "main" java.lang.NullPointerException
at java.util.EnumMap.<init>(EnumMap.java:110)
at com.sun.xml.bind.v2.model.impl.RuntimeEnumLeafInfoImpl.<init>
(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.TypeRefImpl.calcRef
(TypeRefImpl.java:92)
at com.sun.xml.bind.v2.model.impl.TypeRefImpl.getTarget
(TypeRefImpl.java:69)
at com.sun.xml.bind.v2.model.impl.RuntimeTypeRefImpl.getTarget
(RuntimeTypeRefImpl.java:58)
at com.sun.xml.bind.v2.model.impl.RuntimeTypeRefImpl.getTarget
(RuntimeTypeRefImpl.java:51)
at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.get
(ElementPropertyInfoImpl.java:74)
at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.get
(ElementPropertyInfoImpl.java:77)
at java.util.AbstractList$Itr.next(AbstractList.java:422)
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.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:441)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>
(JAXBContextImpl.java:288)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build
(JAXBContextImpl.java:1111)
at com.sun.xml.bind.v2.ContextFactory.createContext
(ContextFactory.java:154)
at com.sun.xml.bind.v2.ContextFactory.createContext
(ContextFactory.java:121)
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 javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at jaxb.Issue.main(Issue.java:22)



 Comments   
Comment by skells [ 19/Mar/09 ]

Created an attachment (id=300)
code to demonstrate the problem

Comment by Martin Grebac [ 11/Sep/09 ]

Thanks for submission. Reassigning to myself, adjusting priority.

Comment by nddipiazza [ 20/Nov/12 ]

I'm experiencing this issue when generating Java from WSDL using the CXF and WSDL2JAVA stuff.

Is there a work around for this?

Here is code generated that causes the problem:

@XmlType(name = "CategoryType")
@XmlEnum
public enum CategoryType {

@XmlEnumValue("None")
NONE("None"),
@XmlEnumValue("Component")
COMPONENT("Component");
private final String value;

CategoryType(String v)

{ value = v; }

public String value()

{ return value; }

public static CategoryType fromValue(String v) {
for (CategoryType c: CategoryType.values()) {
if (c.value.equals(v))

{ return c; }

}
throw new IllegalArgumentException(v);
}

}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CategoryInputType", propOrder =

{ "category" }

)
public class CategoryInputType {

@XmlElement(required = true)
protected CategoryType category;

/**

  • Gets the value of the category property.
  • @return
  • possible object is
  • {@link CategoryType }
    *
    */
    public CategoryType getCategory() { return category; }

    /**
    * Sets the value of the category property.
    *
    * @param value
    * allowed object is
    * {@link CategoryType }
  • */
    public void setCategory(CategoryType value)

    { this.category = value; }

}

Comment by nddipiazza [ 20/Nov/12 ]

Came from:

<simpleType name="CategoryType">
<restriction base="string">
<enumeration value="None" />
<enumeration value="Component" />
</restriction>
</simpleType>

Comment by nddipiazza [ 21/Nov/12 ]

I fixed it by changing any Class that contains an Enum Like the following:

Change this:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CategoryInputType", propOrder =

{ "category" })
public class CategoryInputType {

@XmlElement(required = true)
protected CategoryType category;

/**

•Gets the value of the category property.

•@return
•possible object is
•{@link CategoryType }
*
*/
public CategoryType getCategory() { return category; }

/**
* Sets the value of the category property.
*
* @param value
* allowed object is
* {@link CategoryType }
•*/
public void setCategory(CategoryType value) { this.category = value; }

}

To this:


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CategoryInputType", propOrder = { "category" }

)
public class CategoryInputType {

@XmlElement(required = true)
protected CategoryType category;

/**

•Gets the value of the category property.

•@return
•possible object is

{@link CategoryType }
*
*/
public Enum<CategoryType> getCategory() { return category; }

/**
* Sets the value of the category property.
*
* @param value
* allowed object is
* {@link CategoryType }

•*/
public void setCategory(Enum<CategoryType> value)

{ this.category = (CategoryType)value; }

}

Generated at Sun Feb 07 13:17:08 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.