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

ClassCastException in method org.exolab.castor.xml.schema.writer.SchemaWriter.processSimpleType

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1, 1.1.1, 1.1.2, 1.1.2.1
  • Fix Version/s: 1.3 rc1
  • Component/s: XML
  • Labels:
    None
  • Environment:
    Castor v1.0
    Xerces J v2.6.2
    JDK v1.5.0_06

Description

In class "org.exolab.castor.xml.schema.writer.SchemaWriter", method "processSimpleType", when looking for the base type of a simple type the only call performed is the one prefixed with a star character:
—
private void processSimpleType (SimpleType simpleType, String schemaPrefix) throws SAXException {
[...]
//-- handle restriction

  • SimpleType base = (SimpleType)simpleType.getBaseType();
    boolean isRestriction = false;
    if (base != null)
    Unknown macro: { if (simpleType instanceof ListType) { isRestriction = (base instanceof ListType); } else isRestriction = true; }

    [...]
    }
    —

However, if that reference happens to be null for any reason, then we enter a series of conditions into which the simple element is trusted to be either a union or a list (see lines prefixed with star below):
—
private void processSimpleType (SimpleType simpleType, String schemaPrefix) throws SAXException {
[...]
else if (simpleType instanceof Union) { * processUnion((Union)simpleType, schemaPrefix); }
//-- handle List
else { String ELEM_LIST = schemaPrefix + SchemaNames.LIST; _atts.clear(); * SimpleType itemType = ((ListType)simpleType).getItemType(); [...] }
—

This leads to a potentially invalid cast operation if the simple type isn't one of these though, and unfortunately I got the case, with a simple type being an instance of "org.exolab.castor.xml.schema.DeferredSimpleType", and having a base type defined into another (imported) schema.
This instance had a null reference to its base type, and caused a class cast exception for being casted to a ListType in the code mentionned above.

The fix I made in order to unblock the issue locally is to enable a walk throught the list of imported schemas in order to look for the missing base type reference.
To find the base type instance, I'm using the base type name owned by the simple type that is currently processed.

To gain ability to find the base type name, I augment the class "org.exolab.castor.xml.schema.XMLType" with a getter on it:
—
public String getBaseTypeName() { return baseType != null ? baseType.getName() : null; }
—

Then in class "org.exolab.castor.xml.schema.DeferredSimpleType", which happens to be the one for which the class cast error occurred for me, I override this getter to return the instance field "baseTypeName" :
—
public String getBaseTypeName() { return baseTypeName; }
—

Now we can go back to method "processSimpleType" of class "org.exolab.castor.xml.schema.writer.SchemaWriter" and complement it with an additional attempt of resolving the reference to the base type:
—
private void processSimpleType (SimpleType simpleType, String schemaPrefix) throws SAXException {
[...]
//-- handle restriction
SimpleType base = (SimpleType)simpleType.getBaseType();

// ADDED (BEGIN)
String baseTypeName = simpleType.getBaseTypeName();
if(base == null && baseTypeName != null) { Schema schema = simpleType.getSchema(); * base = getTypeFromSchema(schema, baseTypeName); }
// ADDED (END)

boolean isRestriction = false;
[...]
}
—

The method "getTypeFromSchema" mentiomned on the line prefixed with a star is added to this class as well:
—
private SimpleType getTypeFromSchema(Schema schema, String typeName) {
SimpleType base = schema.getSimpleType(typeName);
if(base == null) {
Enumeration imports = schema.getImportedSchema();
while (imports.hasMoreElements() && base == null) { Schema sch = (Schema) imports.nextElement(); base = getTypeFromSchema(sch, typeName); }
}
return base;
}
—

This allows me to fix the issue, although I'm not sure this is the fix that you guys would apply, since I'm not even sure that this is normal that I got an instance of "org.exolab.castor.xml.schema.DeferredSimpleType" with a null reference to a base type.

Still, if this can be of any help, then all these debugging hours will not be lost.

Thanks & regards,
Alex.

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

Attachments

  1. Hide
    Zip Archive
    bug2279.zip
    29/Jan/08 12:12 PM
    149 kB
    Alexandre Delarge
    1. File
      bug2279/.../DeferredSimpleType.java.diff 0.6 kB
    2. File
      bug2279/patch/.../SchemaWriter.java.diff 3 kB
    3. File
      bug2279/patch/.../schema/XMLType.java.diff 0.6 kB
    4. Text File
      bug2279/README.txt 5 kB
    5. Java Source File
      bug2279/TestClassCastOnDeferredSimpleType.java 1 kB
    6. XML File
      bug2279/xsd/OTA_AirCommonTypes.xsd 136 kB
    7. XML File
      bug2279/xsd/OTA_AirPreferences.xsd 21 kB
    8. XML File
      bug2279/xsd/OTA_CommonPrefs.xsd 12 kB
    9. XML File
      bug2279/xsd/OTA_CommonTypes.xsd 236 kB
    10. XML File
      bug2279/xsd/OTA_HotelAvailRS.xsd 12 kB
    11. XML File
      bug2279/xsd/OTA_HotelCommonTypes.xsd 265 kB
    12. XML File
      bug2279/xsd/OTA_HotelPreferences.xsd 15 kB
    13. XML File
      bug2279/xsd/OTA_HotelReservation.xsd 33 kB
    14. XML File
      bug2279/xsd/OTA_Profile.xsd 19 kB
    15. XML File
      bug2279/xsd/OTA_SimpleTypes.xsd 44 kB
    16. XML File
      bug2279/xsd/OTA_VehicleCommonTypes.xsd 164 kB
    Download Zip
    Show
    Zip Archive
    bug2279.zip
    29/Jan/08 12:12 PM
    149 kB
    Alexandre Delarge
  2. Hide
    Zip Archive
    bug2279-svn.zip
    30/Jan/08 12:03 PM
    149 kB
    Alexandre Delarge
    1. File
      bug2279-svn/.../DeferredSimpleType.java.diff 0.5 kB
    2. File
      bug2279-svn/patch/.../SchemaWriter.java.diff 2 kB
    3. File
      bug2279-svn/patch/.../XMLType.java.diff 0.5 kB
    4. Text File
      bug2279-svn/README.txt 6 kB
    5. Java Source File
      bug2279-svn/TestClassCastOnDeferredSimpleType.java 1 kB
    6. XML File
      bug2279-svn/xsd/OTA_AirCommonTypes.xsd 136 kB
    7. XML File
      bug2279-svn/xsd/OTA_AirPreferences.xsd 21 kB
    8. XML File
      bug2279-svn/xsd/OTA_CommonPrefs.xsd 12 kB
    9. XML File
      bug2279-svn/xsd/OTA_CommonTypes.xsd 236 kB
    10. XML File
      bug2279-svn/xsd/OTA_HotelAvailRS.xsd 12 kB
    11. XML File
      bug2279-svn/xsd/OTA_HotelCommonTypes.xsd 265 kB
    12. XML File
      bug2279-svn/xsd/OTA_HotelPreferences.xsd 15 kB
    13. XML File
      bug2279-svn/xsd/OTA_HotelReservation.xsd 33 kB
    14. XML File
      bug2279-svn/xsd/OTA_Profile.xsd 19 kB
    15. XML File
      bug2279-svn/xsd/OTA_SimpleTypes.xsd 44 kB
    16. XML File
      bug2279-svn/.../OTA_VehicleCommonTypes.xsd 164 kB
    Download Zip
    Show
    Zip Archive
    bug2279-svn.zip
    30/Jan/08 12:03 PM
    149 kB
    Alexandre Delarge
  3. Hide
    Zip Archive
    bug2279-svn-2nd.zip
    31/Jan/08 9:57 AM
    150 kB
    Alexandre Delarge
    1. File
      bug2279-svn/.../DeferredSimpleType.java.diff 0.5 kB
    2. File
      bug2279-svn/patch/.../SchemaWriter.java.diff 2 kB
    3. File
      bug2279-svn/patch/.../XMLType.java.diff 0.5 kB
    4. Text File
      bug2279-svn/README.txt 6 kB
    5. Java Source File
      bug2279-svn/TestClassCastOnDeferredSimpleType.java 1 kB
    6. XML File
      bug2279-svn/xsd/OTA_AirCommonTypes.xsd 136 kB
    7. XML File
      bug2279-svn/xsd/OTA_AirPreferences.xsd 21 kB
    8. XML File
      bug2279-svn/xsd/OTA_CommonPrefs.xsd 12 kB
    9. XML File
      bug2279-svn/xsd/OTA_CommonTypes.xsd 236 kB
    10. XML File
      bug2279-svn/xsd/OTA_HotelAvailRS.xsd 12 kB
    11. XML File
      bug2279-svn/xsd/OTA_HotelCommonTypes.xsd 265 kB
    12. XML File
      bug2279-svn/xsd/OTA_HotelPreferences.xsd 15 kB
    13. XML File
      bug2279-svn/xsd/OTA_HotelReservation.xsd 33 kB
    14. XML File
      bug2279-svn/xsd/OTA_Profile.xsd 19 kB
    15. XML File
      bug2279-svn/xsd/OTA_SimpleTypes.xsd 44 kB
    16. XML File
      bug2279-svn/.../OTA_VehicleCommonTypes.xsd 164 kB
    Download Zip
    Show
    Zip Archive
    bug2279-svn-2nd.zip
    31/Jan/08 9:57 AM
    150 kB
    Alexandre Delarge
  4. Text File
    patch.c2279.20080205.txt
    05/Feb/08 4:37 PM
    4 kB
    Werner Guttmann

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Alexandre Delarge added a comment - 29/Jan/08 12:12 PM

Attached file bug2279 contains the following hierarchy:

  • Instructions for problem reproduction in file "\README.txt"
  • JUnit test case for problem reproduction in "\TestClassCastOnDeferredSimpleType.java"
  • XML Schemas for problem reproduction "\xsd"
  • Suggested patch on 3 classes (diff command under Windows/Cygwin was used):
    • \patch\src\main\java\org\exolab\castor\xml\schema\DeferredSimpleType.java.diff
    • \patch\src\main\java\org\exolab\castor\xml\schema\XMLType.java.diff
    • \patch\src\main\java\org\exolab\castor\xml\schema\writer\SchemaWriter.java.diff
Show
Alexandre Delarge added a comment - 29/Jan/08 12:12 PM Attached file bug2279 contains the following hierarchy:
  • Instructions for problem reproduction in file "\README.txt"
  • JUnit test case for problem reproduction in "\TestClassCastOnDeferredSimpleType.java"
  • XML Schemas for problem reproduction "\xsd"
  • Suggested patch on 3 classes (diff command under Windows/Cygwin was used):
    • \patch\src\main\java\org\exolab\castor\xml\schema\DeferredSimpleType.java.diff
    • \patch\src\main\java\org\exolab\castor\xml\schema\XMLType.java.diff
    • \patch\src\main\java\org\exolab\castor\xml\schema\writer\SchemaWriter.java.diff
Hide
Permalink
Werner Guttmann added a comment - 29/Jan/08 12:24 PM

Thanks, Alexandre, for looking into this in so much detail. Rest assured that your dedication and the time you have put in won't be lost in anyway. Having said that, are you in a position to supply us with a unified patch that you created using 'svn diff' ?

Show
Werner Guttmann added a comment - 29/Jan/08 12:24 PM Thanks, Alexandre, for looking into this in so much detail. Rest assured that your dedication and the time you have put in won't be lost in anyway. Having said that, are you in a position to supply us with a unified patch that you created using 'svn diff' ?
Hide
Permalink
Alexandre Delarge added a comment - 29/Jan/08 1:56 PM

Hi Werner,

I haven't looked at the SVN diff steps yet, is there a great difference between what I could issue using that procedure and the DIFF files in the ZIP archive I attached ?

Those were created using the Cygwin port of the diff command under Windows, and against Castor v1.1.2.1.

If you confirm the need for the SVN version of the patch, let me know and I'll take the time to do it.

Regards,
Alex.

Show
Alexandre Delarge added a comment - 29/Jan/08 1:56 PM Hi Werner, I haven't looked at the SVN diff steps yet, is there a great difference between what I could issue using that procedure and the DIFF files in the ZIP archive I attached ? Those were created using the Cygwin port of the diff command under Windows, and against Castor v1.1.2.1. If you confirm the need for the SVN version of the patch, let me know and I'll take the time to do it. Regards, Alex.
Hide
Permalink
Werner Guttmann added a comment - 29/Jan/08 2:33 PM

I have had some problems in the past integrating 'plain' diffs, but let's see how it goes. I'll ping you again if I am running into problems. What dif you use as a base for the diffs. A SVN ckeckout or a source distro ?

Show
Werner Guttmann added a comment - 29/Jan/08 2:33 PM I have had some problems in the past integrating 'plain' diffs, but let's see how it goes. I'll ping you again if I am running into problems. What dif you use as a base for the diffs. A SVN ckeckout or a source distro ?
Hide
Permalink
Alexandre Delarge added a comment - 29/Jan/08 2:52 PM

Hi Werner,

I used the distribution of the sources, version 1.1.2.1.

Regards,
Alex.

Show
Alexandre Delarge added a comment - 29/Jan/08 2:52 PM Hi Werner, I used the distribution of the sources, version 1.1.2.1. Regards, Alex.
Hide
Permalink
Werner Guttmann added a comment - 29/Jan/08 3:09 PM

No good ... as these sources are more than 8 months old. To be honest, to ease my life, I'd appreciate if you checked out SVN trunk and attached at least diffs built against this code base. 8 months is along time, and as you can see yourself at http://jira.codehaus.org/browse/CASTOR (roadmap), a lot of work has been done and a lot of code committed.

Show
Werner Guttmann added a comment - 29/Jan/08 3:09 PM No good ... as these sources are more than 8 months old. To be honest, to ease my life, I'd appreciate if you checked out SVN trunk and attached at least diffs built against this code base. 8 months is along time, and as you can see yourself at http://jira.codehaus.org/browse/CASTOR (roadmap), a lot of work has been done and a lot of code committed.
Hide
Permalink
Werner Guttmann added a comment - 29/Jan/08 3:09 PM

Btw, if you need help re: SVN checkout, feel free to ping me on the IRC channel or send us emails on the dev list.

Show
Werner Guttmann added a comment - 29/Jan/08 3:09 PM Btw, if you need help re: SVN checkout, feel free to ping me on the IRC channel or send us emails on the dev list.
Hide
Permalink
Alexandre Delarge added a comment - 30/Jan/08 2:54 AM

Hi Werner,

I'll grab the Cygwin port of subversion and will try to release the svn version of these diff files within the day.

Rgds,
Alex.

Show
Alexandre Delarge added a comment - 30/Jan/08 2:54 AM Hi Werner, I'll grab the Cygwin port of subversion and will try to release the svn version of these diff files within the day. Rgds, Alex.
Hide
Permalink
Werner Guttmann added a comment - 30/Jan/08 3:46 AM

Thanks in advance.

Show
Werner Guttmann added a comment - 30/Jan/08 3:46 AM Thanks in advance.
Hide
Permalink
Alexandre Delarge added a comment - 30/Jan/08 12:03 PM

The provided archive "bug2279-svn.zip" contains the same tentative patch as previously sent, except it was made against the available "TRUNK" from subversion as of 30th Jan 2008.

Patch concerns 3 classes, and was generated using the Windows/Cygwin port of the "svn diff" command:

  • \patch\src\main\java\org\exolab\castor\xml\schema\DeferredSimpleType.java.diff
  • \patch\src\main\java\org\exolab\castor\xml\schema\XMLType.java.diff
  • \patch\src\main\java\org\exolab\castor\xml\schema\writer\SchemaWriter.java.diff
Show
Alexandre Delarge added a comment - 30/Jan/08 12:03 PM The provided archive "bug2279-svn.zip" contains the same tentative patch as previously sent, except it was made against the available "TRUNK" from subversion as of 30th Jan 2008. Patch concerns 3 classes, and was generated using the Windows/Cygwin port of the "svn diff" command:
  • \patch\src\main\java\org\exolab\castor\xml\schema\DeferredSimpleType.java.diff
  • \patch\src\main\java\org\exolab\castor\xml\schema\XMLType.java.diff
  • \patch\src\main\java\org\exolab\castor\xml\schema\writer\SchemaWriter.java.diff
Hide
Permalink
Alexandre Delarge added a comment - 30/Jan/08 12:04 PM

Hi Werner,

Let me know if the provided version suits you.

Rgds,
Alex.

Show
Alexandre Delarge added a comment - 30/Jan/08 12:04 PM Hi Werner, Let me know if the provided version suits you. Rgds, Alex.
Hide
Permalink
Werner Guttmann added a comment - 31/Jan/08 3:49 AM

Alexandre, can I please ask you to re-create your patch again. Due to internal discussion, we have decided to move all XML schema related classes to a new (Maven) module. As such, you'll find the source code for the XML schema classes in the new 'schema' sub-directory under the project root. Sorry for any inconvenience caused, but this restructuring was really necessary, as it greatly eases our life during deployment.

Show
Werner Guttmann added a comment - 31/Jan/08 3:49 AM Alexandre, can I please ask you to re-create your patch again. Due to internal discussion, we have decided to move all XML schema related classes to a new (Maven) module. As such, you'll find the source code for the XML schema classes in the new 'schema' sub-directory under the project root. Sorry for any inconvenience caused, but this restructuring was really necessary, as it greatly eases our life during deployment.
Hide
Permalink
Werner Guttmann added a comment - 31/Jan/08 3:50 AM

In addition, can I ask you why you are enlisting Xerces 2.6.2 as dependency in the environment section. As you are on Java 5.0, Xerces comes shipped with the JDK/JRE by default. Just being curious here .....

Show
Werner Guttmann added a comment - 31/Jan/08 3:50 AM In addition, can I ask you why you are enlisting Xerces 2.6.2 as dependency in the environment section. As you are on Java 5.0, Xerces comes shipped with the JDK/JRE by default. Just being curious here .....
Hide
Permalink
Alexandre Delarge added a comment - 31/Jan/08 7:20 AM

Hi Werner,

I'll make one last patch as you ask, later this day I hope.

For Xerces this is due to the tool I debugged and that relied onto a specific suite of components:

  • Castor v1.0
  • Xerces J v2.6.2
  • JDK v1.5.0_06
  • SAAJ v1.2
  • Axis v1.4
  • etc.

For some reason this tool uses Xerces-J to parse the result of a schema serialization made with castor.
I imagine this is to provide Xerces with a schema that contains all definitions for a given schema + the definitions ones defined into the imported schemas.

Cheers,
Alex.

Show
Alexandre Delarge added a comment - 31/Jan/08 7:20 AM Hi Werner, I'll make one last patch as you ask, later this day I hope. For Xerces this is due to the tool I debugged and that relied onto a specific suite of components:
  • Castor v1.0
  • Xerces J v2.6.2
  • JDK v1.5.0_06
  • SAAJ v1.2
  • Axis v1.4
  • etc.
For some reason this tool uses Xerces-J to parse the result of a schema serialization made with castor. I imagine this is to provide Xerces with a schema that contains all definitions for a given schema + the definitions ones defined into the imported schemas. Cheers, Alex.
Hide
Permalink
Alexandre Delarge added a comment - 31/Jan/08 9:57 AM

As requested, provided archive "bug2279-svn-2nd.zip" contains a tentative patch made against "TRUNK" subversion as of 31th Jan 2008.

Patch concerns 3 classes, and was generated using the Windows/Cygwin port of the "svn diff" command:

  • \bug2279-svn\patch\castor\castor\trunk\schema\src\main\java\org\exolab\castor\xml\schema\DeferredSimpleType.java.diff
  • \bug2279-svn\patch\castor\castor\trunk\schema\src\main\java\org\exolab\castor\xml\schema\XMLType.java.diff
  • \bug2279-svn\patch\castor\castor\trunk\schema\src\main\java\org\exolab\castor\xml\schema\writer\SchemaWriter.java.diff
Show
Alexandre Delarge added a comment - 31/Jan/08 9:57 AM As requested, provided archive "bug2279-svn-2nd.zip" contains a tentative patch made against "TRUNK" subversion as of 31th Jan 2008. Patch concerns 3 classes, and was generated using the Windows/Cygwin port of the "svn diff" command:
  • \bug2279-svn\patch\castor\castor\trunk\schema\src\main\java\org\exolab\castor\xml\schema\DeferredSimpleType.java.diff
  • \bug2279-svn\patch\castor\castor\trunk\schema\src\main\java\org\exolab\castor\xml\schema\XMLType.java.diff
  • \bug2279-svn\patch\castor\castor\trunk\schema\src\main\java\org\exolab\castor\xml\schema\writer\SchemaWriter.java.diff
Hide
Permalink
Alexandre Delarge added a comment - 31/Jan/08 9:58 AM

Werner,

Please find attached the adjusted patch you requested.

Rgds,
Alex.

Show
Alexandre Delarge added a comment - 31/Jan/08 9:58 AM Werner, Please find attached the adjusted patch you requested. Rgds, Alex.
Hide
Permalink
Werner Guttmann added a comment - 05/Feb/08 4:37 PM

Unified patch against ./schema. In addition, all tests run successfully.

Show
Werner Guttmann added a comment - 05/Feb/08 4:37 PM Unified patch against ./schema. In addition, all tests run successfully.

People

  • Assignee:
    Werner Guttmann
    Reporter:
    Alexandre Delarge
Vote (0)
Watch (1)

Dates

  • Created:
    29/Jan/08 11:19 AM
    Updated:
    24/Jan/09 11:13 AM
    Resolved:
    05/Feb/08 5:16 PM

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
0m
Remaining Estimate - 0 minutes
Logged:
20m
Time Spent - 20 minutes
  • 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.