jaxb
  1. jaxb
  2. JAXB-807

fixedAttributeAsConstantProperty="true" causes NullPointerException

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.10
    • Fix Version/s: None
    • Component/s: xjc
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: All

    • Issuezilla Id:
      30

      Description

      Hi,

      I am running version 0.7.1 of the plugin using Eclipse 3.4.1.

      I have defined an external bindings file as follows:

      <jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
      version="2.0"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">

      <jxb:globalBindings>
      <jxb:javaType name="java.lang.Integer" xmlType="xsd:integer" />
      <jxb:javaType name="java.lang.Boolean" xmlType="xsd:boolean" />
      <jxb:javaType name="java.lang.Long" xmlType="xsd:long" />
      </jxb:globalBindings>

      <jxb:bindings schemaLocation="ReportTypes.xsd" node="/xsd:schema">
      <jxb:bindings node="//xsd:attribute[@name='listref']">
      <jxb:property fixedAttributeAsConstantProperty="true"/>
      </jxb:bindings>
      </jxb:bindings>

      </jxb:bindings>

      Within the ReportTypes.xsd schema file, I have defined the following attribute:

      <xsd:attribute name="listref" type="xsd:string" fixed="10"/>

      When I run the generate goal using Eclipse, I get the following exception:

      java.lang.NullPointerException
      at com.sun.codemodel.JInvocation.generate(JInvocation.java:148)
      at com.sun.codemodel.JFormatter.g(JFormatter.java:330)
      at com.sun.codemodel.JFormatter.g(JFormatter.java:343)
      at com.sun.codemodel.JInvocation.generate(JInvocation.java:157)
      at com.sun.codemodel.JFormatter.g(JFormatter.java:330)
      at com.sun.codemodel.JInvocation.state(JInvocation.java:170)
      at com.sun.codemodel.JFormatter.s(JFormatter.java:366)
      at com.sun.codemodel.JBlock.generateBody(JBlock.java:429)
      at com.sun.codemodel.JBlock.generate(JBlock.java:417)
      at com.sun.codemodel.JFormatter.g(JFormatter.java:330)
      at com.sun.codemodel.JBlock.state(JBlock.java:445)
      at com.sun.codemodel.JFormatter.s(JFormatter.java:366)
      at com.sun.codemodel.JMethod.declare(JMethod.java:423)
      at com.sun.codemodel.JFormatter.d(JFormatter.java:356)
      at com.sun.codemodel.JDefinedClass.declareBody(JDefinedClass.java:791)
      at com.sun.codemodel.JDefinedClass.declare(JDefinedClass.java:764)
      at com.sun.codemodel.JFormatter.d(JFormatter.java:356)
      at com.sun.codemodel.JDefinedClass.declareBody(JDefinedClass.java:795)
      at com.sun.codemodel.JDefinedClass.declare(JDefinedClass.java:764)
      at com.sun.codemodel.JFormatter.d(JFormatter.java:356)
      at com.sun.codemodel.JFormatter.write(JFormatter.java:386)
      at com.sun.codemodel.JPackage.build(JPackage.java:411)
      at com.sun.codemodel.JCodeModel.build(JCodeModel.java:281)
      at com.sun.codemodel.JCodeModel.build(JCodeModel.java:271)
      at org.jvnet.jaxb2.maven2.RawXJC2Mojo.writeCode(RawXJC2Mojo.java:670)
      at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:260)
      at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:134)
      at
      org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:579)
      at
      org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498)
      at
      org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmentForProject(DefaultLifecycleExecutor.java:265)
      at
      org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:191)
      at
      org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:149)
      at org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223)
      at org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
      at
      org.apache.maven.embedder.MavenEmbedder.execute_aroundBody2(MavenEmbedder.java:904)
      at
      org.apache.maven.embedder.MavenEmbedder.execute_aroundBody3$advice(MavenEmbedder.java:304)
      at org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:176)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:63)
      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:597)
      at
      org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
      at
      org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:408)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:351)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:31)

      When I change fixedAttributeAsConstantProperty to false in the bindings file,
      the plugin runs fine.

      All I am trying to achieve is a String constant in my generated Java code.
      e.g.
      public final static String LISTREF = "10";

        Activity

        Hide
        lexi added a comment -

        I don't think this has anything to do with the maven-jaxb2-plugin, this must be a JAXB XJC problem. I'll forward the issue.

        Show
        lexi added a comment - I don't think this has anything to do with the maven-jaxb2-plugin, this must be a JAXB XJC problem. I'll forward the issue.
        Hide
        Martin Grebac added a comment -

        Would you please provide reproducible testcase? Thanks.

        Show
        Martin Grebac added a comment - Would you please provide reproducible testcase? Thanks.
        Hide
        boz0413 added a comment -

        Test case:

        test.xsd
        ========

        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ABCT="http://abc.com/types" targetNamespace="http://abc.com/types" elementFormDefault="qualified" attributeFormDefault="unqualified">

        <xsd:element name="MyRequest" type="ABCT:MyStructure"/>

        <xsd:complexType name="MyStructure">
        <xsd:sequence>
        <xsd:element name="flag" type="xsd:boolean"/>
        </xsd:sequence>
        <xsd:attribute name="listref" type="xsd:string" fixed="10"/>
        </xsd:complexType>

        </xsd:schema>

        test.xjb
        ========
        <bindings xmlns="http://java.sun.com/xml/ns/jaxb"
        version="2.0"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">

        <globalBindings>
        <javaType name="java.lang.Integer" xmlType="xsd:integer" />
        <javaType name="java.lang.Boolean" xmlType="xsd:boolean" />
        <javaType name="java.lang.Long" xmlType="xsd:long" />
        </globalBindings>

        <bindings schemaLocation="test.xsd" node="/xsd:schema">
        <bindings node="//xsd:attribute[@name='listref']">
        <property fixedAttributeAsConstantProperty="true"/>
        </bindings>
        </bindings>

        </bindings>

        If I run the following on the command line:

        xjc -d gen -b test.xjb test.xsd

        then the expected Java class com.abc.types.MyStructure is created in the gen directory. Specifically, the attribute is declared as a constant.

        ...
        @XmlAttribute
        public final static String LISTREF = "10";
        ...

        For this reason, I don't think xjc is the problem.

        Now, if I try to run the maven command 'mvn generate-resources' with the same setup using version 0.7.1 of maven-jaxb2-plugin, I get the aforementioned stack trace. If I change the bindings file so that fixedAttributeAsConstantProperty="false" then there is no error on generation but a correct Java constant is NOT created. Instead you get:

        ...
        @XmlAttribute
        protected String listref;
        ...

        public String getListref() {
        if (listref == null)

        { return "10"; }

        else

        { return listref; }

        }
        ...
        public void setListref(String value)

        { this.listref = value; }
        Show
        boz0413 added a comment - Test case: test.xsd ======== <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ABCT="http://abc.com/types" targetNamespace="http://abc.com/types" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:element name="MyRequest" type="ABCT:MyStructure"/> <xsd:complexType name="MyStructure"> <xsd:sequence> <xsd:element name="flag" type="xsd:boolean"/> </xsd:sequence> <xsd:attribute name="listref" type="xsd:string" fixed="10"/> </xsd:complexType> </xsd:schema> test.xjb ======== <bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <globalBindings> <javaType name="java.lang.Integer" xmlType="xsd:integer" /> <javaType name="java.lang.Boolean" xmlType="xsd:boolean" /> <javaType name="java.lang.Long" xmlType="xsd:long" /> </globalBindings> <bindings schemaLocation="test.xsd" node="/xsd:schema"> <bindings node="//xsd:attribute [@name='listref'] "> <property fixedAttributeAsConstantProperty="true"/> </bindings> </bindings> </bindings> If I run the following on the command line: xjc -d gen -b test.xjb test.xsd then the expected Java class com.abc.types.MyStructure is created in the gen directory. Specifically, the attribute is declared as a constant. ... @XmlAttribute public final static String LISTREF = "10"; ... For this reason, I don't think xjc is the problem. Now, if I try to run the maven command 'mvn generate-resources' with the same setup using version 0.7.1 of maven-jaxb2-plugin, I get the aforementioned stack trace. If I change the bindings file so that fixedAttributeAsConstantProperty="false" then there is no error on generation but a correct Java constant is NOT created. Instead you get: ... @XmlAttribute protected String listref; ... public String getListref() { if (listref == null) { return "10"; } else { return listref; } } ... public void setListref(String value) { this.listref = value; }

          People

          • Assignee:
            Martin Grebac
            Reporter:
            boz0413
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: