Details
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.
-
Hide
- bug2279.zip
- 29/Jan/08 12:12 PM
- 149 kB
- Alexandre Delarge
-
- bug2279/.../DeferredSimpleType.java.diff 0.6 kB
- bug2279/patch/.../SchemaWriter.java.diff 3 kB
- bug2279/patch/.../schema/XMLType.java.diff 0.6 kB
- bug2279/README.txt 5 kB
- bug2279/TestClassCastOnDeferredSimpleType.java 1 kB
- bug2279/xsd/OTA_AirCommonTypes.xsd 136 kB
- bug2279/xsd/OTA_AirPreferences.xsd 21 kB
- bug2279/xsd/OTA_CommonPrefs.xsd 12 kB
- bug2279/xsd/OTA_CommonTypes.xsd 236 kB
- bug2279/xsd/OTA_HotelAvailRS.xsd 12 kB
- bug2279/xsd/OTA_HotelCommonTypes.xsd 265 kB
- bug2279/xsd/OTA_HotelPreferences.xsd 15 kB
- bug2279/xsd/OTA_HotelReservation.xsd 33 kB
- bug2279/xsd/OTA_Profile.xsd 19 kB
- bug2279/xsd/OTA_SimpleTypes.xsd 44 kB
- bug2279/xsd/OTA_VehicleCommonTypes.xsd 164 kB
-
Hide
- bug2279-svn.zip
- 30/Jan/08 12:03 PM
- 149 kB
- Alexandre Delarge
-
- bug2279-svn/.../DeferredSimpleType.java.diff 0.5 kB
- bug2279-svn/patch/.../SchemaWriter.java.diff 2 kB
- bug2279-svn/patch/.../XMLType.java.diff 0.5 kB
- bug2279-svn/README.txt 6 kB
- bug2279-svn/TestClassCastOnDeferredSimpleType.java 1 kB
- bug2279-svn/xsd/OTA_AirCommonTypes.xsd 136 kB
- bug2279-svn/xsd/OTA_AirPreferences.xsd 21 kB
- bug2279-svn/xsd/OTA_CommonPrefs.xsd 12 kB
- bug2279-svn/xsd/OTA_CommonTypes.xsd 236 kB
- bug2279-svn/xsd/OTA_HotelAvailRS.xsd 12 kB
- bug2279-svn/xsd/OTA_HotelCommonTypes.xsd 265 kB
- bug2279-svn/xsd/OTA_HotelPreferences.xsd 15 kB
- bug2279-svn/xsd/OTA_HotelReservation.xsd 33 kB
- bug2279-svn/xsd/OTA_Profile.xsd 19 kB
- bug2279-svn/xsd/OTA_SimpleTypes.xsd 44 kB
- bug2279-svn/.../OTA_VehicleCommonTypes.xsd 164 kB
-
Hide
- bug2279-svn-2nd.zip
- 31/Jan/08 9:57 AM
- 150 kB
- Alexandre Delarge
-
- bug2279-svn/.../DeferredSimpleType.java.diff 0.5 kB
- bug2279-svn/patch/.../SchemaWriter.java.diff 2 kB
- bug2279-svn/patch/.../XMLType.java.diff 0.5 kB
- bug2279-svn/README.txt 6 kB
- bug2279-svn/TestClassCastOnDeferredSimpleType.java 1 kB
- bug2279-svn/xsd/OTA_AirCommonTypes.xsd 136 kB
- bug2279-svn/xsd/OTA_AirPreferences.xsd 21 kB
- bug2279-svn/xsd/OTA_CommonPrefs.xsd 12 kB
- bug2279-svn/xsd/OTA_CommonTypes.xsd 236 kB
- bug2279-svn/xsd/OTA_HotelAvailRS.xsd 12 kB
- bug2279-svn/xsd/OTA_HotelCommonTypes.xsd 265 kB
- bug2279-svn/xsd/OTA_HotelPreferences.xsd 15 kB
- bug2279-svn/xsd/OTA_HotelReservation.xsd 33 kB
- bug2279-svn/xsd/OTA_Profile.xsd 19 kB
- bug2279-svn/xsd/OTA_SimpleTypes.xsd 44 kB
- bug2279-svn/.../OTA_VehicleCommonTypes.xsd 164 kB
-
- patch.c2279.20080205.txt
- 05/Feb/08 4:37 PM
- 4 kB
- Werner Guttmann
Activity
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' ?
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.
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 ?
Hi Werner,
I used the distribution of the sources, version 1.1.2.1.
Regards,
Alex.
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.
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.
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.
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
- \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
Hi Werner,
Let me know if the provided version suits you.
Rgds,
Alex.
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.
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 .....
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.
- Castor v1.0
- Xerces J v2.6.2
- JDK v1.5.0_06
- SAAJ v1.2
- Axis v1.4
- etc.
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
- \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
Werner,
Please find attached the adjusted patch you requested.
Rgds,
Alex.
Unified patch against ./schema. In addition, all tests run successfully.
Attached file bug2279 contains the following hierarchy: