jaxb-v2
jaxb-v2 copied to clipboard
"trying to create the same field twice" error doesn't report line number
Try downloading all of the XML Schema files from the web page linked above and then run xjc on CDA.xsd to generate the equivalent Java code. It will fail with this error.
Exception in thread "main" java.lang.IllegalArgumentException: trying to create
the same field twice: id
at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:419)
at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:390)
at com.sun.tools.xjc.generator.bean.field.AbstractFieldWithVar.createField
(AbstractFieldWithVar.java:71)
at com.sun.tools.xjc.generator.bean.field.SingleField.
The error message is correct, but not helpful. In all other cases when there is an error in an XML Schema file, xjc reports the exact line number where the problem exists. It should also report the line number for a duplicate field name. That would have made it much easier to identify the underlying problem. (For a full description see this discussion thread: http://forums.java.net/jive/message.jspa?messageID=278722 .)
Environment
Operating System: All Platform: All URL: http://www.hl7.org/v3ballot/html/infrastructure/cda/cda.htm#CDA_Schema
Affected Versions
[2.1.7]
Reported by nradov
snajper said: exception shall be caught and rethrown with current location
scarcher2 said: I'm having the same problem. Trying to generate classes from the CDA Schema files.
Issue-Links: blocks JAXB-508
Was assigned to snajper
This issue was imported from java.net JIRA JAXB-512
Still a problem in 2.2.8-b130911.1802 10 years later.