jaxb-ri
jaxb-ri copied to clipboard
NullPointerException in AbstractField.annotateReference():188
The given XSD
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="2.1"
jaxb:extensionBindingPrefixes="xjc"
elementFormDefault="qualified">
<xsd:annotation>
<xsd:appinfo>
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType name="item">
<xsd:attribute name="level" type="xsd:integer" use="required">
<xsd:annotation>
<xsd:appinfo>
<jaxb:property>
<jaxb:baseType name="int" />
</jaxb:property>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="comment" type="markup" />
<xsd:complexType name="markup" mixed="true">
<xsd:annotation>
<xsd:appinfo>
<jaxb:class name="Style" />
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element ref="comment" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
when compiled with XJC v2.2.11 (also tried v2.2.4 and v2.2.8) causes NPE:
D:\jaxb-ri\bin\xjc.bat -extension test.xsd
parsing a schema...
[WARNING] Cannot generate default value for primitive type "int".
line 19 of file:/D:/test.xsd
compiling a schema...
Exception in thread "main" java.lang.NullPointerException
at com.sun.tools.xjc.generator.bean.field.AbstractField.annotateReference(AbstractField.java:188)
at com.sun.tools.xjc.generator.bean.field.AbstractField.annotate(AbstractField.java:161)
at com.sun.tools.xjc.generator.bean.field.AbstractListField.generate(AbstractListField.java:129)
at com.sun.tools.xjc.generator.bean.field.UntypedListField.<init>(UntypedListField.java:112)
at com.sun.tools.xjc.generator.bean.field.UntypedListFieldRenderer.generate(UntypedListFieldRenderer.java:77)
at com.sun.tools.xjc.generator.bean.field.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:82)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:777)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:558)
at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:261)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:169)
at com.sun.tools.xjc.model.Model.generateCode(Model.java:288)
at com.sun.tools.xjc.Driver.run(Driver.java:384)
at com.sun.tools.xjc.Driver.run(Driver.java:221)
at com.sun.tools.xjc.Driver._main(Driver.java:144)
at com.sun.tools.xjc.Driver.access$000(Driver.java:82)
at com.sun.tools.xjc.Driver$1.run(Driver.java:103)
Affected Versions
[2.2.11]
- Issue Imported From: https://github.com/javaee/jaxb-v2/issues/1108
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @glassfishrobot
@glassfishrobot Commented Reported by dma_k
@glassfishrobot Commented dma_k said: Actually the problematic XSD is simpler:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="2.1"
jaxb:extensionBindingPrefixes="xjc"
elementFormDefault="qualified">
<xsd:annotation>
<xsd:appinfo>
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="comment" type="markup" />
<xsd:complexType name="markup" mixed="true">
<xsd:annotation>
<xsd:appinfo>
<jaxb:class name="Style" />
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element ref="comment" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
which means that problem occurs when there is a circular dependency in the type and type class name is customized.
@glassfishrobot Commented Was assigned to yaroska
@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-1108
Problem still occurs on latest version of XJC (4.0.4-SNAPSHOT tested)
Caused by: java.lang.NullPointerException: Cannot invoke "javax.xml.namespace.QName.getLocalPart()" because the return value of "com.sun.tools.xjc.model.CElement.getElementName()" is null
at com.sun.tools.xjc.generator.bean.field.AbstractField.annotateReference (AbstractField.java:163)
at com.sun.tools.xjc.generator.bean.field.AbstractField.annotate (AbstractField.java:136)
at com.sun.tools.xjc.generator.bean.field.AbstractListField.generate (AbstractListField.java:105)
at com.sun.tools.xjc.generator.bean.field.UntypedListField.<init> (UntypedListField.java:83)
at com.sun.tools.xjc.generator.bean.field.UntypedListFieldRenderer.generate (UntypedListFieldRenderer.java:48)
The problematic part is the following customization :
<xsd:annotation>
<xsd:appinfo>
<jaxb:class name="Style" />
</xsd:appinfo>
</xsd:annotation>