gradle-xjc-plugin icon indicating copy to clipboard operation
gradle-xjc-plugin copied to clipboard

<jaxb:globalBindings optionalProperty="primitive"> causes NullPointerException

Open Andrey-Metelyov opened this issue 2 years ago • 1 comments

When i add xsd:annotation block with <jaxb:globalBindings optionalProperty="primitive">, exception occurs:

Execution failed for task ':xjcGenerate'.
> A failure occurred while executing org.unbrokendome.gradle.plugins.xjc.work.xjc23.XjcGeneratorWorkAction
   > java.lang.NullPointerException (no error message)

example of modified Books.xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://unbroken-dome.org/gradle-xjc-plugin/samples/books"
            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
            jaxb:version="1.0"
            targetNamespace="http://unbroken-dome.org/gradle-xjc-plugin/samples/books">

  <xsd:annotation>
    <xsd:appinfo>
      <jaxb:globalBindings optionalProperty="primitive">
        <jaxb:serializable/>
      </jaxb:globalBindings>
    </xsd:appinfo>
  </xsd:annotation>

  <xsd:complexType name="bookType">
    <xsd:attribute name="title" type="xsd:string"/>
    <xsd:attribute name="author" type="xsd:string"/>
    <xsd:attribute name="bestseller" type="xsd:boolean"/>
    <xsd:attribute name="publicationYear" type="xsd:gYear"/>
  </xsd:complexType>

  <xsd:element name="book" type="tns:bookType"/>

  <xsd:complexType name="booksType">
    <xsd:sequence>
      <xsd:element ref="tns:book"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:element name="books" type="tns:booksType"/>

</xsd:schema>

Andrey-Metelyov avatar Aug 03 '22 10:08 Andrey-Metelyov

Thanks for this report.

I quick look at this, can you confirm if you see a root cause exception from the XJC tool itself, or only the NPE, so the NPE is blocking the real root cause from your view ?

If you can only see the NPE then please report the Java version, XJB version in use when it occurred.

A quick test of this on here and maybe the NPE matter is fixed (indirectly) from the updated plugin using the patches from #47

However this issue report does highlight that better diagnostic output to the user is needed if an exception is thrown from XJB through doExecute() in the plugin. Such as making it clear to the user where the issue is (the com.sun.tool.xjc code of the XJC tool) and to report the runtime environment details, JVM, XJB tool version, XJC classpath, verbosely to help with filing bug reports like this.

To accept this as a bug report for the plugin to address you need to prove the command line tool XJC can be run with the same configuration without throwing the exception and producing expected output results for your use case. This is because I believe the NPE matter to be fixed via PR #47 as I could no recreate it but I know little of the environment you used to see the error.

Please provide a ZIP file mini-project test case (using the XJB command line tool directly, without gradle or this plugin) to validate the processing you request from XJC works without the plugin, also confirm JVM, XJC and classpath JARs needed so it can be reproduced.

I believe the issue is a problem with the XJC tool and/or misconfiguration as the root cause shown here when I perform the test your request (edit samples/**/basic/**/book.xsd and run integrationTest) I get the following exception:

    Caused by: java.lang.AssertionError
        at com.sun.tools.xjc.generator.bean.field.UnboxedField.<init>(UnboxedField.java:47)
        at com.sun.tools.xjc.generator.bean.field.GenericFieldRenderer.generate(GenericFieldRenderer.java:39)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:753)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:534)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:233)
        at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:141)
        at com.sun.tools.xjc.model.Model.generateCode(Model.java:258)
        at org.unbrokendome.gradle.plugins.xjc.work.common.AbstractXjcGeneratorWorkAction.doExecute(AbstractXjcGeneratorWorkAction.kt:114)
        at org.unbrokendome.gradle.plugins.xjc.work.common.AbstractXjcGeneratorWorkAction.execute(AbstractXjcGeneratorWorkAction.kt:53)
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)

dlmiles avatar Dec 10 '23 01:12 dlmiles