jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • castor
  • CASTOR-385

Source Generator uses the name "Content" which conflicts with any element named "Content."

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 0.9.4.2, 1.0, 1.0.1, 1.0.2, 1.0.3
  • Fix Version/s: 1.0.4
  • Component/s: XML code generator
  • Labels:
    None
  • Environment:
    Operating System: Linux
    Platform: Sun
  • Bugzilla Id:
    1243

Description

This NullPointerException turns up when generating java source for the STMML
schema (www.xml-cml.org/schema/stmml):

Exception in thread "main" java.lang.NullPointerException
at org.exolab.castor.builder.TypeConversion.compare(TypeConversion.java:522)
at
org.exolab.castor.builder.TypeConversion.findCommonType(TypeConversion.java:506)
at
org.exolab.castor.builder.TypeConversion.convertType(TypeConversion.java:100)
at
org.exolab.castor.builder.binding.XMLBindingComponent.getJavaType(XMLBindingComponent.java:1103)
at
org.exolab.castor.builder.MemberFactory.createFieldInfo(MemberFactory.java:221)
at
org.exolab.castor.builder.SourceFactory.processAttributes(SourceFactory.java:1213)
at
org.exolab.castor.builder.SourceFactory.processComplexType(SourceFactory.java:1295)
at
org.exolab.castor.builder.SourceFactory.createSourceCode(SourceFactory.java:326)
at
org.exolab.castor.builder.SourceGenerator.createClasses(SourceGenerator.java:1249)
at
org.exolab.castor.builder.SourceGenerator.createClasses(SourceGenerator.java:1186)
at
org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:490)
at
org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:549)
at
org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:580)
at org.exolab.castor.builder.SourceGenerator.main(SourceGenerator.java:1135)

Applying this patch makes it go again:

— src/main/org/exolab/castor/builder/TypeConversion.java.original Thu Mar
6 10:04:57 2003
+++ src/main/org/exolab/castor/builder/TypeConversion.java Thu Mar 6
10:04:16 2003
@@ -518,6 +518,9 @@

  • if the types are not compatable.
    */
    private static SimpleType compare(SimpleType aType, SimpleType bType) {
    + if (aType == null) return bType;
    + if (bType == null) return aType;
    +
    int type1 = aType.getTypeCode();
    int type2 = bType.getTypeCode();

Hopefully this is useful,

kind regards,

Egon Willighagen

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    castor-385.patch
    14/Oct/06 10:53 PM
    28 kB
    Edward Kuns
  2. File
    castor-385-final.diff
    15/Oct/06 9:55 PM
    40 kB
    Edward Kuns

Issue Links

relates to

Bug - A problem which impairs or prevents the functions of the product. CASTOR-1421 xsd:integer is not correctly mapped to BigInteger (java.lang.NumberFormatException)

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Keith Visco added a comment - 07/Mar/03 2:35 AM

Thanks Egon, I'll review the patch and get it into the CVS soon.

Show
Keith Visco added a comment - 07/Mar/03 2:35 AM Thanks Egon, I'll review the patch and get it into the CVS soon.
Hide
Permalink
Keith Visco added a comment - 07/Mar/03 2:38 AM

Created an attachment (id=254)
The schema causing the error (stmml.xsd)

Show
Keith Visco added a comment - 07/Mar/03 2:38 AM Created an attachment (id=254) The schema causing the error (stmml.xsd)
Hide
Permalink
Andrew Fawcett added a comment - 09/May/05 12:11 PM

Downloaded stmml.xsd from www.xml-cml.org/schema/stmml

Had to make following changes
a) Remove <xsd:minInclusive> and <xsd:MaxInclusive> from "countType" <xsd:simpleType>
b) Had to remove "content" attribute from "metadata" <xsd:element>
c) Had to remove <h2> element from <xsd:enumeration> in "metadataType" <xsd:simpleType>

Than ran Source Generator (without binding file) without issues.

Looking at stack trace could have been issue with binding file being used.

Suspect a) and c) could be bugs in the schema, but will keep call open to address b).

Show
Andrew Fawcett added a comment - 09/May/05 12:11 PM Downloaded stmml.xsd from www.xml-cml.org/schema/stmml Had to make following changes a) Remove <xsd:minInclusive> and <xsd:MaxInclusive> from "countType" <xsd:simpleType> b) Had to remove "content" attribute from "metadata" <xsd:element> c) Had to remove <h2> element from <xsd:enumeration> in "metadataType" <xsd:simpleType> Than ran Source Generator (without binding file) without issues. Looking at stack trace could have been issue with binding file being used. Suspect a) and c) could be bugs in the schema, but will keep call open to address b).
Hide
Permalink
Werner Guttmann added a comment - 08/Oct/06 6:29 AM

Edward, can you attach whatever you have currently ?

Show
Werner Guttmann added a comment - 08/Oct/06 6:29 AM Edward, can you attach whatever you have currently ?
Hide
Permalink
Edward Kuns added a comment - 09/Oct/06 11:24 AM

I don't have anything to attach. I only have my investigation for CASTOR-1580. Do you think this is related?

Show
Edward Kuns added a comment - 09/Oct/06 11:24 AM I don't have anything to attach. I only have my investigation for CASTOR-1580. Do you think this is related?
Hide
Permalink
Edward Kuns added a comment - 10/Oct/06 12:42 AM

Ignore my previous comment. I was thinking of a different issue and trying to respond too quickly. I hadn't yet done anything on this issue.

Show
Edward Kuns added a comment - 10/Oct/06 12:42 AM Ignore my previous comment. I was thinking of a different issue and trying to respond too quickly. I hadn't yet done anything on this issue.
Hide
Permalink
Werner Guttmann added a comment - 10/Oct/06 4:45 AM

Ignore my last comment as well ... with hindsight, I have no idea as to why I asked you .. ?

Show
Werner Guttmann added a comment - 10/Oct/06 4:45 AM Ignore my last comment as well ... with hindsight, I have no idea as to why I asked you .. ?
Hide
Permalink
Edward Kuns added a comment - 12/Oct/06 7:31 PM

a) above is the fact that xsd:integer is represented by Castor by an int, not by a BigInteger. aka, CASTOR-1421
b) above is probably a bug in the source generator
c) above must be a bug in the schema.

I'm looking into b).

Show
Edward Kuns added a comment - 12/Oct/06 7:31 PM a) above is the fact that xsd:integer is represented by Castor by an int, not by a BigInteger. aka, CASTOR-1421 b) above is probably a bug in the source generator c) above must be a bug in the schema. I'm looking into b).
Hide
Permalink
Edward Kuns added a comment - 12/Oct/06 7:50 PM

b) above is a bug because we create a field _content in the method createFieldInfoForContent(XSType, boolean) in MemberFactory.java. This means that any use of an element that will map to the class name Content will clash with this field. A mapping file will fix this, but probably we shouldn't use such an obvious name for our field for internal use.

In addition to my comment here and above, the source generator generates code for me that won't compile because this schema uses names such as Array and Object. (Of course, Andrew said that sourcegen ran without issue. He didn't say that the code it generated would compile.

This brings up the question: What should Castor do when one is not using a binding file and names that overlap names of java.lang.* will be generated? Should we check for conflicts with java.lang.* so we can provide a meaningful complaint?

I will drop the priority of this issue from critical to minor, because at least with our current release, a mapping file will solve all blocking problems encountered other than CASTOR-1421, which is already tracked elsewhere. I don't see the exception above, so I agree with Andrew that it must have been an artifact of the binding file used.

Show
Edward Kuns added a comment - 12/Oct/06 7:50 PM b) above is a bug because we create a field _content in the method createFieldInfoForContent(XSType, boolean) in MemberFactory.java. This means that any use of an element that will map to the class name Content will clash with this field. A mapping file will fix this, but probably we shouldn't use such an obvious name for our field for internal use. In addition to my comment here and above, the source generator generates code for me that won't compile because this schema uses names such as Array and Object. (Of course, Andrew said that sourcegen ran without issue. He didn't say that the code it generated would compile. This brings up the question: What should Castor do when one is not using a binding file and names that overlap names of java.lang.* will be generated? Should we check for conflicts with java.lang.* so we can provide a meaningful complaint? I will drop the priority of this issue from critical to minor, because at least with our current release, a mapping file will solve all blocking problems encountered other than CASTOR-1421, which is already tracked elsewhere. I don't see the exception above, so I agree with Andrew that it must have been an artifact of the binding file used.
Hide
Permalink
Werner Guttmann added a comment - 14/Oct/06 4:53 AM

I think that we should actually check for naming collisions with java.lang.*, and at least report an error similar to how naming conflicts are reported already. Given that this will casue uncompilable code any how ( which might not happen with other naming collisions), why not even go a step further and refuse code generation at all ? Yes, the naming of the '_element' is a bit dd, but it conveys a concept that otherwise would be hidden behind a ridiculous variable name.

Show
Werner Guttmann added a comment - 14/Oct/06 4:53 AM I think that we should actually check for naming collisions with java.lang.*, and at least report an error similar to how naming conflicts are reported already. Given that this will casue uncompilable code any how ( which might not happen with other naming collisions), why not even go a step further and refuse code generation at all ? Yes, the naming of the '_element' is a bit dd, but it conveys a concept that otherwise would be hidden behind a ridiculous variable name.
Hide
Permalink
Ralf Joachim added a comment - 14/Oct/06 5:57 AM

I have seen a class that checks names for collisions with reserved words of java somewhere. I think we can extend that one to also check for some other reserved names that we need internaly.

Show
Ralf Joachim added a comment - 14/Oct/06 5:57 AM I have seen a class that checks names for collisions with reserved words of java somewhere. I think we can extend that one to also check for some other reserved names that we need internaly.
Hide
Permalink
Werner Guttmann added a comment - 14/Oct/06 6:04 AM

And if you only could remember where .. .

Show
Werner Guttmann added a comment - 14/Oct/06 6:04 AM And if you only could remember where .. .
Hide
Permalink
Ralf Joachim added a comment - 14/Oct/06 6:12 AM

It's org.exolab.javasource.JNaming

Show
Ralf Joachim added a comment - 14/Oct/06 6:12 AM It's org.exolab.javasource.JNaming
Hide
Permalink
Edward Kuns added a comment - 14/Oct/06 12:15 PM

I'll look into extending JNaming to also look for java.lang.* clashes, and I'll treat those errors as fatal srcgen errors if no mapping is used. I'll also look into a different name for _content that is not obscure or long but is less likely to conflict with user-generated, well, content.

Show
Edward Kuns added a comment - 14/Oct/06 12:15 PM I'll look into extending JNaming to also look for java.lang.* clashes, and I'll treat those errors as fatal srcgen errors if no mapping is used. I'll also look into a different name for _content that is not obscure or long but is less likely to conflict with user-generated, well, content.
Hide
Permalink
Edward Kuns added a comment - 14/Oct/06 10:53 PM

Attaching a patch that resolves the conflict with members of java.lang.*

Thoughts?

Show
Edward Kuns added a comment - 14/Oct/06 10:53 PM Attaching a patch that resolves the conflict with members of java.lang.* Thoughts?
Hide
Permalink
Werner Guttmann added a comment - 15/Oct/06 4:41 AM

Edward, ignoring the patch for a few minutes, I am definitely in favor of fixing naming collisions with 'java.lang.' classes. On the second issue, we have to keep in mind that any changes to the signature of the classes generated should be as *minimal as possible. People - I asume - will have coded against getContent() for months, if not years.

Show
Werner Guttmann added a comment - 15/Oct/06 4:41 AM Edward, ignoring the patch for a few minutes, I am definitely in favor of fixing naming collisions with 'java.lang.' classes. On the second issue, we have to keep in mind that any changes to the signature of the classes generated should be as *minimal as possible. People - I asume - will have coded against getContent() for months, if not years.
Hide
Permalink
Werner Guttmann added a comment - 15/Oct/06 4:52 AM

Given patch looks good to me ...

Show
Werner Guttmann added a comment - 15/Oct/06 4:52 AM Given patch looks good to me ...
Hide
Permalink
Ralf Joachim added a comment - 15/Oct/06 5:20 AM

+1

Show
Ralf Joachim added a comment - 15/Oct/06 5:20 AM +1
Hide
Permalink
Edward Kuns added a comment - 15/Oct/06 11:30 AM

Werner, I hadn't yet explored whether the "content" variable was one with an external interface that could be called. Now I know that it does. That means the most appropriate way to fix that issue is to check for naming collisions and provide a meaningful complaint.

Show
Edward Kuns added a comment - 15/Oct/06 11:30 AM Werner, I hadn't yet explored whether the "content" variable was one with an external interface that could be called. Now I know that it does. That means the most appropriate way to fix that issue is to check for naming collisions and provide a meaningful complaint.
Hide
Permalink
Edward Kuns added a comment - 15/Oct/06 9:55 PM

Attaching final patch.

Show
Edward Kuns added a comment - 15/Oct/06 9:55 PM Attaching final patch.
Hide
Permalink
Edward Kuns added a comment - 15/Oct/06 9:56 PM

Fix applied. For conflicts with java.lang.*, source generation throws an exception. For conflicts with "Content" source generation prints a warning but does not throw an exception, as the Content field that Castor uses is not always generated.

Show
Edward Kuns added a comment - 15/Oct/06 9:56 PM Fix applied. For conflicts with java.lang.*, source generation throws an exception. For conflicts with "Content" source generation prints a warning but does not throw an exception, as the Content field that Castor uses is not always generated.

People

  • Assignee:
    Edward Kuns
    Reporter:
    egonw
Vote (0)
Watch (0)

Dates

  • Created:
    06/Mar/03 2:22 AM
    Updated:
    22/Oct/06 3:21 PM
    Resolved:
    15/Oct/06 9:56 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.