[JAXP-30] none value recognition of minOccurs and maxOccurs Created: 16/Apr/07  Updated: 16/Apr/07  Resolved: 16/Apr/07

Status: Resolved
Project: jaxp
Component/s: www
Affects Version/s: current
Fix Version/s: milestone 1

Type: Bug Priority: Major
Reporter: suchtdenfehler Assignee: Santiago Pericas-Geertsen
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Issuezilla Id: 30

 Description   

I have an application where xml streams needs to be validated against xsd-schemas.
Using JDK 1.5 (jdk1.5.0_07) this works well and the streams are correctly validated.

When I use Java 1.6 (build 1.6.0-b105) the minOccurs and maxOccurs seams to be
skipped from the validation process and the xml is always reported as valid.

Here is a snippet of my code:

File xmlFile = new File("occurs.xml");

SchemaFactory factory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File("occurs.xsd"));

// get a DOM factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// configure the factory
dbf.setNamespaceAware(true);

// set schema on the factory
dbf.setSchema(schema);

DocumentBuilder documentBuilder = dbf.newDocumentBuilder();

// Check the document
try {
documentBuilder.parse(xmlFile);
System.out.println(xmlFile.getName() + " is valid.");
}
catch (SAXException ex) {
System.out.println(xmlFile.getName() + " is not valid because ");
System.out.println(ex.getMessage());
}

// And the corresponding xml and xsd.

occurs.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<persons>

<person>
<full_name>Hege Refsnes</full_name>
<child_name>Cecilie</child_name>
</person>

<person>
<full_name>Tove Refsnes</full_name>
<child_name>Hege</child_name>
<child_name>Stale</child_name>
<child_name>Jim</child_name>
<child_name>Borge</child_name>
</person>

<person>
<full_name>Stale Refsnes</full_name>
</person>

</persons>

occurs.xsd

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

<xs:element name="persons">
<xs:complexType>
<xs:sequence>
<xs:element name="person" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" minOccurs="0"
maxOccurs="3"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Java 1.5 reports:
occurs.xml is not valid because
cvc-complex-type.2.4.d: Invalid content was found starting with element
'child_name'. No child element is expected at this point.

while Java 1.6 reports:
occurs.xml is valid.

I browsed the JAXP Project Page to find the differences from JAXP 1.3 is
included in J2SE 5.0 and the implementation of JAXP 1.4 is part of Java SE 6.0
but found nothing linked to my problem.



 Comments   
Comment by Santiago Pericas-Geertsen [ 16/Apr/07 ]

Some code has changed in JDK 6.0, so this may indeed be a new issue in JDK 6.0.

Comment by Santiago Pericas-Geertsen [ 16/Apr/07 ]

As demonstrated in the test case of JAXP issue 30, the constant-space algorithm for validating a

{n,m}
cannot be applied when an FSA is created to accept a content model that includes, but it is not just a{n,m}

.
In other words, the optimization introduce for a

{n,m}

was a bit too aggressive and had to be restricted.

Note that the testcase should use an ErrorHandler to receive validation errors; catching a SAXException is
not enought. This patch will be available in the JAXP 1.4.1 nightly build available from this site (see
Downloads section).

Generated at Tue May 05 02:31:20 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.