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)
//-- handle List
else
—
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()
—
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()
—
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)
// 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)
}
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