FULL PRODUCT VERSION :
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux caius.datanomic.local 2.6.9-42.0.2.ELsmp #1 SMP Wed Aug 23 13:38:27 BST 2006 x86_64 x86_64 x86_64 GNU/Linux
Microsoft Windows [Version 6.0.6001]
A DESCRIPTION OF THE PROBLEM :
A valid XML file fails validation against a schema which defines a nested element with minOccurs="2" and maxOccurs="2".
The output is similar to that in bug 6457662 but this seems to be different. It happens even without schema reuse.
Does not occur with J2SE 1.5 but _does_ occur with 1.6u12 early access and 1.7 early access.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached test. The schema contains:
<xs:element ref='baseItem' minOccurs='2' maxOccurs='2'/>
The sample XML is valid against the schema but fails with a message implying that the limit of 2 elements has been exceeded.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No error message
ACTUAL -
An exception
ERROR MESSAGES/STACK TRACES THAT OCCUR :
org.xml.sax.SAXParseException: cvc-complex-type.2.4.d: Invalid content was found starting with element '{baseItem}'. No child element is expected at this point.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.StringReader;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.SchemaFactory;
import org.xml.sax.SAXParseException;
public class maxerr {
private static final String SCHEMA =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
" <xs:element name='item' substitutionGroup='baseItem'>" +
" <xs:complexType>" +
" <xs:complexContent>" +
" <xs:extension base='baseItemType'>" +
" <xs:sequence>" +
" <xs:element ref='baseItem' minOccurs='2' maxOccurs='2'/>" +
" </xs:sequence>" +
" </xs:extension>" +
" </xs:complexContent>" +
" </xs:complexType>" +
" </xs:element>" +
"" +
" <xs:element name='leaf' substitutionGroup='baseItem'>" +
" <xs:complexType>" +
" <xs:complexContent>" +
" <xs:extension base='baseItemType'/>" +
" </xs:complexContent>" +
" </xs:complexType>" +
" </xs:element>" +
"" +
" <xs:element name='baseItem' abstract='true' type='baseItemType'/>" +
" <xs:complexType name='baseItemType'/>" +
"</xs:schema>";
private static final String XML =
"<item>" +
" <leaf/>" +
" <item>" +
" <item><leaf/><leaf/></item>" +
" <leaf/>" +
" </item>" +
"</item>";
public static void main(String ... args) throws Exception {
Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new StreamSource(new StringReader(SCHEMA)));
try {
schema.newValidator().validate(new StreamSource(new StringReader(XML)));
} catch (SAXParseException e) {
System.out.println(e);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Replace:
<xs:element ref='baseItem' minOccurs='2' maxOccurs='2'/>
with:
<xs:element ref='baseItem'/>
<xs:element ref='baseItem'/>
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux caius.datanomic.local 2.6.9-42.0.2.ELsmp #1 SMP Wed Aug 23 13:38:27 BST 2006 x86_64 x86_64 x86_64 GNU/Linux
Microsoft Windows [Version 6.0.6001]
A DESCRIPTION OF THE PROBLEM :
A valid XML file fails validation against a schema which defines a nested element with minOccurs="2" and maxOccurs="2".
The output is similar to that in bug 6457662 but this seems to be different. It happens even without schema reuse.
Does not occur with J2SE 1.5 but _does_ occur with 1.6u12 early access and 1.7 early access.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached test. The schema contains:
<xs:element ref='baseItem' minOccurs='2' maxOccurs='2'/>
The sample XML is valid against the schema but fails with a message implying that the limit of 2 elements has been exceeded.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No error message
ACTUAL -
An exception
ERROR MESSAGES/STACK TRACES THAT OCCUR :
org.xml.sax.SAXParseException: cvc-complex-type.2.4.d: Invalid content was found starting with element '{baseItem}'. No child element is expected at this point.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.StringReader;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.SchemaFactory;
import org.xml.sax.SAXParseException;
public class maxerr {
private static final String SCHEMA =
"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
" <xs:element name='item' substitutionGroup='baseItem'>" +
" <xs:complexType>" +
" <xs:complexContent>" +
" <xs:extension base='baseItemType'>" +
" <xs:sequence>" +
" <xs:element ref='baseItem' minOccurs='2' maxOccurs='2'/>" +
" </xs:sequence>" +
" </xs:extension>" +
" </xs:complexContent>" +
" </xs:complexType>" +
" </xs:element>" +
"" +
" <xs:element name='leaf' substitutionGroup='baseItem'>" +
" <xs:complexType>" +
" <xs:complexContent>" +
" <xs:extension base='baseItemType'/>" +
" </xs:complexContent>" +
" </xs:complexType>" +
" </xs:element>" +
"" +
" <xs:element name='baseItem' abstract='true' type='baseItemType'/>" +
" <xs:complexType name='baseItemType'/>" +
"</xs:schema>";
private static final String XML =
"<item>" +
" <leaf/>" +
" <item>" +
" <item><leaf/><leaf/></item>" +
" <leaf/>" +
" </item>" +
"</item>";
public static void main(String ... args) throws Exception {
Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new StreamSource(new StringReader(SCHEMA)));
try {
schema.newValidator().validate(new StreamSource(new StringReader(XML)));
} catch (SAXParseException e) {
System.out.println(e);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Replace:
<xs:element ref='baseItem' minOccurs='2' maxOccurs='2'/>
with:
<xs:element ref='baseItem'/>
<xs:element ref='baseItem'/>
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.