Issue Details (XML | Word | Printable)

Key: JAXB-615
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Iaroslav Savytskyi
Reporter: skells
Votes: 3
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
jaxb

JAXBContext.newInstance fails with NPE if class has an Enum

Created: 19/Mar/09 02:38 PM   Updated: 21/Nov/12 03:40 PM
Component/s: runtime
Affects Version/s: 2.1.8
Fix Version/s: not determined

Time Tracking:
Not Specified

File Attachments: 1. Java Source File Issue.java (0.7 kB) 19/Mar/09 02:40 PM - skells

Environment:

Operating System: All
Platform: All


Issuezilla Id: 615
Tags:
Participants: Iaroslav Savytskyi, Martin Grebac, nddipiazza, skells and vpl_atol


 Description  « Hide

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)



skells added a comment - 19/Mar/09 02:40 PM

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


Martin Grebac added a comment - 11/Sep/09 05:03 AM

Thanks for submission. Reassigning to myself, adjusting priority.


nddipiazza added a comment - 20/Nov/12 06:56 PM

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; }

}


nddipiazza added a comment - 20/Nov/12 08:38 PM

Came from:

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


nddipiazza added a comment - 21/Nov/12 03:40 PM

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; }

}