question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jaxb:globalBindings optionalProperty="primitive" causes NullPointer in xjc

See original GitHub issue
**bindings.xml**<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> 
    <jaxb:globalBindings optionalProperty="primitive" />
</jaxb:bindings>
**APPTransactionData.xsd**<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema	targetNamespace="http://www.agr.gc.ca/APP" 			xmlns:app="http://www.agr.gc.ca/APP" 			xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

	<xs:complexType name="Shareholder_Type">
		<xs:sequence>
			<xs:element name="Controlling_Member" type="xs:boolean" minOccurs="0" maxOccurs="1"/>
			<xs:element name="Producer_Reference_Id" type="app:Producer_Reference_Id_Type"/>
		</xs:sequence>	
	</xs:complexType>

	<xs:simpleType name="Producer_Reference_Id_Type">
		<xs:restriction base="xs:string" />
	</xs:simpleType>

</xs:schema>
**build.xml**	<xjc 	destdir="${schema.source.dir}"
			schema="APPTransactionData.xsd"
			binding="bindings.xml"
			package="${schema.generated.package}">

My intent here is to force isControllingMember() method have a primitive boolean return type, as opposed to Boolean.

Running my Ant task causes this exception:

java.lang.NullPointerException
        at com.sun.codemodel.JVar.annotate(JVar.java:188)
        at com.sun.codemodel.TypedAnnotationWriter.create(TypedAnnotationWriter.java:247)
        at com.sun.codemodel.JVar.annotate2(JVar.java:192)
        at com.sun.tools.xjc.generator.bean.field.AbstractField.getXew(AbstractField.java:354)
        at com.sun.tools.xjc.generator.bean.field.AbstractField.writeXmlElementAnnotation(AbstractField.java:286)
        at com.sun.tools.xjc.generator.bean.field.AbstractField.annotateElement(AbstractField.java:242)
        at com.sun.tools.xjc.generator.bean.field.AbstractField.annotate(AbstractField.java:157)
        at com.sun.tools.xjc.generator.bean.field.AbstractFieldWithVar.createField(AbstractFieldWithVar.java:79)
        at com.sun.tools.xjc.generator.bean.field.UnboxedField.<init>(UnboxedField.java:79)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at com.sun.tools.xjc.generator.bean.field.GenericFieldRenderer.generate(GenericFieldRenderer.java:69)
        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.XJC2Task._doXJC(XJC2Task.java:524)
        at com.sun.tools.xjc.XJC2Task.doXJC(XJC2Task.java:457)
        at com.sun.tools.xjc.XJC2Task.execute(XJC2Task.java:380)
        at com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:103)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

If I modify bindings.xml like this:

**bindings.xml**<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1">

    <jaxb:globalBindings optionalProperty="primitive" generateIsSetMethod="false" />
</jaxb:bindings>

then my ShareholderType class gets successfully generated. Unfortunately, adding generateIsSetMethod attribute causes optionalProperty=“primitive” not to work anymore for the boolean field (now the return type on isControllingMember() is Boolean), so this is not a workaround.

Environment

java version “1.7.0_51” Java™ SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot™ 64-Bit Server VM (build 24.51-b03, mixed mode)

Apache Ant™ version 1.8.2 compiled on December 3 2011

Affected Versions

[2.2.11]

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
davidmotencommented, Jan 11, 2019

I’m hitting this problem. What’s the plan here?

0reactions
Tomas-Krauscommented, Sep 21, 2018

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-1073

Read more comments on GitHub >

github_iconTop Results From Across the Web

jaxb:globalBindings optionalProperty="primitive" causes ...
My intent here is to force isControllingMember() method have a primitive boolean return type, as opposed to Boolean. ... then my ShareholderType ...
Read more >
JAXB attribute with Object type throwing null pointer exception?
A property of type Object would not round trip anyways as unlike elements, attributes do not have any mechanisms to include typing information....
Read more >
Re: force to use primitive types - Oracle
3) ran xjc -b binding.xjb po.xsd ... optionalProperty controls how a JAXB property with a primitive ... It leads to NPE in my...
Read more >
JAXB Release Documentation - Java EE
Running the binding compiler (XJC): [XJC, XJC Ant Task] ... JAXB-926 - Fixed optional property behavior for PRIMITIVE value.
Read more >
Fix list for IBM WebSphere Application Server V8.5
PH34972, Invalid properties in the ra.xml causes websphere v8.5.5.x resource adapter ... Administrative Console (all non-scripting), PI78907, Null pointer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found