patrodyne / hisrc-basicjaxb

XJC plugins and tools for JAXB.
BSD 3-Clause "New" or "Revised" License
15 stars 6 forks source link

DefaultValuePlugin: IllegalArgumentException when elements come with an inline anonymous type definition #21

Open mgrobarek opened 7 months ago

mgrobarek commented 7 months ago

I’m currently migrating to your default value xjc plugin when I encountered the following problem:

[main] INFO org.jvnet.basicjaxb.plugin.defaultvalue.DefaultValuePlugin - XJC> XdefaultValue: : Start
Parameters
  Verbose.: true
  Debug...: true
[main] ERROR org.jvnet.basicjaxb.plugin.defaultvalue.DefaultValuePlugin - XJC> XdefaultValue: IllegalArgumentException: local part cannot be "null" when creating a QName
[main] INFO org.jvnet.basicjaxb.plugin.defaultvalue.DefaultValuePlugin - XJC> XdefaultValue: : Finish
Results
  HadError.: true

WSDLToJava Error: Error during plugin execution.

org.apache.cxf.tools.common.ToolException: Error during plugin execution.

    at org.apache.cxf.tools.common.ToolErrorListener.throwToolException(ToolErrorListener.java:87)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:149)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:402)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
    at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
    at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
    at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:184)
Caused by: org.xml.sax.SAXParseException; Error during plugin execution.
    at org.jvnet.basicjaxb.plugin.AbstractPlugin.handleException(AbstractPlugin.java:135)
    at org.jvnet.basicjaxb.plugin.AbstractPlugin.run(AbstractPlugin.java:264)
    at com.sun.tools.xjc.model.Model.generateCode(Model.java:263)
    at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:265)
    at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:65)
    at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:445)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.generateTypes(WSDLToJavaContainer.java:711)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:259)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:146)
    ... 5 more
Caused by: java.lang.IllegalArgumentException: local part cannot be "null" when creating a QName
    at java.xml/javax.xml.namespace.QName.<init>(QName.java:185)
    at java.xml/javax.xml.namespace.QName.<init>(QName.java:129)
    at org.jvnet.basicjaxb.plugin.defaultvalue.DefaultValuePlugin.processClassOutline(DefaultValuePlugin.java:325)
    at org.jvnet.basicjaxb.plugin.defaultvalue.DefaultValuePlugin.run(DefaultValuePlugin.java:231)
    at org.jvnet.basicjaxb.plugin.AbstractPlugin.run(AbstractPlugin.java:259)
    ... 12 more

This happens for the following element definition:

<xsd:element name="Limit" default="1000" minOccurs="0">
    <xsd:simpleType>
        <xsd:restriction base="xsd:int">
            <xsd:minInclusive value="1" />
            <xsd:maxInclusive value="10000" />
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>

The simpleType used for the Limit element has no name, hence the QName cannot be instantiated in DefaultValuePlugin.java:325. I can work around this issue by adding an explicit name for the inline type in my XSD, like this: <xsd:simpleType name="LimitInt">

But in my case, the XSD comes from outside my project and I can’t change it on my own. Hence it would be nice to have the DefaultValuePlugin to ignore such empty names.

I’m using:

patrodyne commented 7 months ago

Thank you for reporting this issue. A new commit 5be585a includes your Limit example, in the unit test, and a modification to DefaultValuePlugin to handle anonymous types. It will be included in the next release (no ETA).

SebGuillomon commented 6 months ago

Hello,

I faced the same issue and default value is a key featurefor me. When is planned version 2.2.1 ?

Many thanks

patrodyne commented 6 months ago

I believe the current release period will be shorter than past periods. Note: I refrain from guessing ETAs.

patrodyne commented 5 months ago

The DefaultValuePlugin has been released to Maven Central.

SebGuillomon commented 5 months ago

Thanks for release,

Using Maven plugin "org.patrodyne.jvnet:hisrc-higherjaxb-maven-plugin:2.2.0" with this dependency (only this release available), I have this error

[ERROR] Failed to execute goal org.patrodyne.jvnet:hisrc-higherjaxb-maven-plugin:2.2.0:generate (default) on project plma-tools-commons: Execution default of goal org.patrodyne.jvnet:hisrc-higherjaxb-maven-plugin:2.2.0:generate failed: An API incompatibility was encountered while executing org.patrodyne.jvnet:hisrc-higherjaxb-maven-plugin:2.2.0:generate: java.lang.NoSuchMethodError: 'boolean org.jvnet.basicjaxb.util.FieldUtils.isConstantField(com.sun.tools.xjc.outline.FieldOutline)'

patrodyne commented 5 months ago

The hisrc-higherjaxb-maven-plugin v2.2.1 should be available to you.