javaee / jaxb2-commons

JAXB Implementation project has been contributed to Eclipse Foundation. This repository is for legacy review only. Please refer to the Eclipse EE4J Metro project for the very latest
https://eclipse-ee4j.github.io/jaxb-ri/
Other
17 stars 15 forks source link

The fluent plugin 2.0.3 generates bad code #5

Closed glassfishrobot closed 17 years ago

glassfishrobot commented 17 years ago

While generating Java code off XHTML schema with xjc, the fluent plugin generated:

class AType{ ....

public AType withType(String[]... values) { for (String value: values)

{ getType().add(value); }

return this; } }

but it should have generated "withType(String... values)". The resulting code does not compile!

Environment

Operating System: All Platform: All

Affected Versions

[current]

glassfishrobot commented 17 years ago

Reported by hr_stoyanov

glassfishrobot commented 17 years ago

hchar said: Can you please attach or provide a link to the specific xsd that triggered this problem ? Thanks.

glassfishrobot commented 17 years ago

hchar said: I just tried the fluent api plugin against the xhtml xsd I could find at:

http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd

I could generate all the sources with the fluent API and compile succesfully. I couldn't reproduce the problem you encountered.

Can you please attach or email me a copy of the XSD that caused you this problem ? Thanks.

glassfishrobot commented 17 years ago

hchar said: Reassign to myself

glassfishrobot commented 17 years ago

hchar said: I'll be closing this issue shortly, unless I can provided with an xsd that can reproduce the problem.

glassfishrobot commented 17 years ago

hchar said: Closing issue. Feel free to reopen it if an XSD can be provided to have the problem reproduced.

glassfishrobot commented 17 years ago

hr_stoyanov said: ...Sorry I have missed your questions. In addition to the original report, I also suspect that this generated code (one of many such) is wrong as well, but it compiles at lease:

class CodeType{ ..... public CodeType withContent(Serializable[]... values) { for (Serializable value: values)

{ getContent().add(value); }

return this; } ... }


I am using version 2.0.3 of the fluent API and the generated code is for the XHTML schema found in here: http://www.w3.org/TR/2004/WD-xhtml-modularization-20040218/

Inside this page, there is a link for a zip archive. Unpack it and try this for SCHEMA\xhtml11.xsd:

glassfishrobot commented 17 years ago

hchar said: Your xjc ant target makes me wonder which version of jaxb/xjc you are using, for there is no "target" attribute for the "xjc" ant task, "destdir" rather. See http://java.sun.com/webservices/docs/2.0/jaxb/xjcTask.html

Anyway, I just tried out the fluent api plugins both on jaxb-ri-20070413 (ie jaxb 2.1.3), jaxb-ri-20061211 (ie jaxb 2.1) and jaxb-ri-20070122 (ie jaxb 2.0.5) against xhtml11.xsd and they all work as expected. Note I changed the xjc ant target to become something like:

<xjc destdir="$

{src.dir}

" removeOldOutput="yes" package="com.peruncs.jaxb_xhtml">

Using jaxb-fluent-api-2.0.3.jar, it generates:

public CodeType withContent(Serializable... values) { for (Serializable value: values)

{ getContent().add(value); }

return this; }

Using jaxb-fluent-api-2.1.3.jar, it generates:

public CodeType withContent(Serializable... values) { if (values!= null) { for (Serializable value: values)

{ getContent().add(value); }

} return this; }

glassfishrobot commented 17 years ago

hchar said: For some reason I don't seem to be able to reproduce this problem. I wonder if anyone else has encountered it.

glassfishrobot commented 17 years ago

hr_stoyanov said: I use the JAXB2.0 library in NetBeans 5.5. The problem still exists even if I upgrade to the 2.1.3 fluent api. Otherwise, I tried to upgrade to Jaxb 2.1.3 and changed the task to be:

---------------------------------------------- But then I started getting the below exception after running Ant (with the most verbose option): ---------------------------------------- ... Finding class org.jvnet.jaxb2_commons.tools.xjc.plugin.fluent_api.XjcFluentApiPlugin Loaded from C:\projects\trunk\jaxbfluent213_wrapper\jaxb-fluent-api-2.1.3.jar org/jvnet/jaxb2_commons/tools/xjc/plugin/fluent_api/XjcFluentApiPlugin.class Finding class com.sun.tools.xjc.Plugin Loaded from C:\projects\trunk\jaxws211_wrapper\lib\jaxb-xjc.jar com/sun/tools/xjc/Plugin.class Class com.sun.tools.xjc.Plugin loaded from ant loader (parentFirst) Class org.jvnet.jaxb2_commons.tools.xjc.plugin.fluent_api.XjcFluentApiPlugin loaded from ant loader (parentFirst) Resource com/sun/tools/xjc/addon/locator/SourceLocationAddOn.class loaded from ant loader Resource com/sun/tools/xjc/addon/sync/SynchronizedMethodAddOn.class loaded from ant loader Resource com/sun/tools/xjc/addon/at_generated/PluginImpl.class loaded from ant loader Resource com/sun/tools/xjc/addon/episode/PluginImpl.class loaded from ant loader Resource com/sun/tools/xjc/addon/episode/PluginImpl$1.class loaded from ant loader Resource com/sun/xml/xsom/visitor/XSFunction.class loaded from ant loader Resource com/sun/xml/xsom/visitor/XSContentTypeFunction.class loaded from ant loader Resource com/sun/xml/xsom/visitor/XSTermFunction.class loaded from ant loader Class java.lang.reflect.Array loaded from parent loader (parentFirst) Resource com/sun/tools/xjc/BadCommandLineException.class loaded from ant loader Class java.lang.Exception loaded from parent loader (parentFirst) failure in the XJC task. Use the Ant -verbose switch for more details Class java.lang.UnsupportedClassVersionError loaded from parent loader (parentFirst) Class java.lang.InstantiationException loaded from parent loader (parentFirst) Class java.lang.IllegalAccessException loaded from parent loader (parentFirst) Class java.io.IOException loaded from parent loader (parentFirst) C:\projects\trunk\jaxb_xhtml11\build.xml:83: unrecognized parameter -Xfluent-api at com.sun.tools.xjc.XJC2Task._doXJC(XJC2Task.java:428) at com.sun.tools.xjc.XJC2Task.doXJC(XJC2Task.java:416) at com.sun.tools.xjc.XJC2Task.execute(XJC2Task.java:351) at com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:55) I only re-open the issue so you could test it with NB 5.5, if you can ...
glassfishrobot commented 17 years ago

hchar said: No problem. Feel free to re-open this issue. However, it smells like a NetBean specific problem. I never used NB but rather direct ant 1.6.5+ build with Java 5 and Jaxb 2.x.

glassfishrobot commented 17 years ago

hr_stoyanov said: Ok, but have you ever try it with JDK1.6 - this is what I am using? I eliminated the NB5.5 JAXWS2.0 jars completely, suspecting they have bad/old XJC code there. But how can you explain the 'unrecognized parameter -Xfluent-api' problem?

My theory is that Sun made a huge mistake by including JAX-WS 2.0 in the jdk1.6. Then they came up with a very ugly patch (http://weblogs.java.net/blog/kohsuke/archive/2007/02/howitworks_runn.html) to make the JAX-WS2.1 jars work. So I think the the above exception is due to some classloader mess.

Btw, where is the link for 2.0.x fluent API download?

glassfishrobot commented 17 years ago

hr_stoyanov said: Ok. I got fluent-2.1.3 to work with Jaxb 2.0.5, eliminating the NB 5.5 bundled JAXWS2.0 module. All under Java 6.

However, there still seems to be a problem with fluent-2.1.3 and JAxb-2.1.3 under java 6. I will file a separate issue for this, if it is not too much for asking you to take a look at it. Thanks.

glassfishrobot commented 17 years ago

hchar said:

have you ever try it with JDK1.6

No I haven't. I avoid using jdk1.6 and jaxb together. I concur that it is a big mistake. Jaxb was going really well until it was included in the jdk. What a mess

where is the link for 2.0.x fluent API download?

They are all located with URL of the pattern:

https://jaxb2-commons.dev.java.net/fluent-api/release/2.0.x/jaxb-fluent-api-2.0.x.jar

(Just substitute "x" with the actual version number)

glassfishrobot commented 17 years ago

hchar said: Since this is a Java 6 related issue, I am closing this issue for now, and leave the other new issue (specific to the use of fluent API under Java 6) open.

glassfishrobot commented 17 years ago

Was assigned to hchar

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA JAXB2_COMMONS-5

glassfishrobot commented 17 years ago

Marked as won't fix on Monday, May 14th 2007, 1:34:48 pm