Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.2
-
Fix Version/s: 1.3 rc1
-
Component/s: XML code generator
-
Labels:None
-
Environment:Windows 2000 SP4, JDK 1.6.0_03-b05
-
Number of attachments :
Description
The return type of generated enumerate<Element> and iterate<Element> methods breaks inheritance for restricted types if <Element> is a restricted type as well.
To reproduce, just generate the source code from the attached XSD (which doesn't make much sense in itself, but is, however, a stripped down version of a real world XSD) by running
java org.exolab.castor.builder.SourceGeneratorMain -types j2 -i enumerate_iterate_bug.xsd
with the appropriate castorbuilder.properties file.
The generated class SomeRestrictedType won't compile as the return type of the enumerateSomeElement() and iterateSomeElement() methods is incompatible with the return type of the same methods in the superclass SomeType.
SomeType:
public java.util.Enumeration<SomeOtherType> enumerateSomeElement()
public java.util.Iterator<SomeOtherType> iterateSomeElement() {...}
SomeRestrictedType:
public java.util.Enumeration<SomeOtherRestrictedType> enumerateSomeElement()
public java.util.Iterator<SomeOtherRestrictedType> iterateSomeElement() {...}
To resolve this issue, the respective return types could be broadened by "? extends", which would lead to the following code:
SomeType:
public java.util.Enumeration<? extends SomeOtherType> enumerateSomeElement()
public java.util.Iterator<? extends SomeOtherType> iterateSomeElement() {...}
SomeRestrictedType:
public java.util.Enumeration<? extends SomeOtherRestrictedType> enumerateSomeElement()
public java.util.Iterator<? extends SomeOtherRestrictedType> iterateSomeElement() {...}
Not sure whether this is the best approach one could take, but it's what I did by hand-editing the generated code to make it work in my case...
Initial patch for review.