eclipse-ee4j / jaxb-ri

Jaxb RI
https://eclipse-ee4j.github.io/jaxb-ri/
BSD 3-Clause "New" or "Revised" License
201 stars 110 forks source link

fixedAttributeAsConstantProperty="true" causes NullPointerException #807

Open Tomas-Kraus opened 14 years ago

Tomas-Kraus commented 14 years ago

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">

Within the ReportTypes.xsd schema file, I have defined the following attribute: 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"; #### Environment Operating System: Windows XP Platform: All #### Affected Versions [2.1.10]
Tomas-Kraus commented 5 years ago
Tomas-Kraus commented 14 years ago

@glassfishrobot Commented Reported by boz0413

Tomas-Kraus commented 13 years ago

@glassfishrobot Commented lexi said: 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.

Tomas-Kraus commented 13 years ago

@glassfishrobot Commented snajper said: Would you please provide reproducible testcase? Thanks.

Tomas-Kraus commented 13 years ago

@glassfishrobot Commented boz0413 said: Test case:

test.xsd

test.xjb ======== 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; }
Tomas-Kraus commented 14 years ago

@glassfishrobot Commented Was assigned to snajper

Tomas-Kraus commented 7 years ago

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