-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
6.0
-
generic
-
generic
Name: erR10175 Date: 02/04/2004
Identity-constraint validation does not regard the field order.
The new JCK-15 beta2 test adopted from W3C XSTC-20020116 testsuite:
api/xml_schema/msxsdtest/identityConstraint/idH012.html#idH012_i
declares a key and a keyref. The keyref's fields are the same that of the referenced
key, but have different order. When the instance document is validated,
fields of the key are evaluated to the the following key-sequence: (1, a),
Fields of the keyref are evaluated to the the following key-sequence: (a, 1).
Those key sequences are not equal and there is no other key
in the context of the keyref. So the rule 4.3 of the Validation Rule: Identity-constraint
Satisfied (see the XML Schema Structures, Section 3.11.6 Constraints on Identity-constraint
Definition Schema Components) is violated in the test instance document but the RI does not
report any error.
The bug is found in jdk1.5.0/beta/b35.
To reproduce the bug compile and run the following code as shown in the log below.
------------------------------------------- test.xml
<?xml version="1.0"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<kid val="1" val2="a"/>
<uid val2="a" val="1"/>
</root>
----------------------------------------------------
------------------------------------------- test.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="kid" maxOccurs="unbounded"/>
<xsd:element ref="uid" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:keyref name="kruid" refer="kuid">
<xsd:selector xpath=".//uid"/>
<xsd:field xpath="@val"/>
<xsd:field xpath="@val2"/>
</xsd:keyref>
<xsd:key name="kuid">
<xsd:selector xpath=".//kid"/>
<xsd:field xpath="@val2"/>
<xsd:field xpath="@val"/>
</xsd:key>
</xsd:element>
<xsd:element name="uid">
<xsd:complexType>
<xsd:attribute name="val" type="xsd:string"/>
<xsd:attribute name="val2" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="kid">
<xsd:complexType>
<xsd:attribute name="val" type="xsd:string"/>
<xsd:attribute name="val2" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
----------------------------------------------------
------------------------------------------ test.java
import java.io.File;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
public class test {
protected static class ErrorHandler extends DefaultHandler {
public int errorCounter = 0;
public void error(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
public void fatalError(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
}
public static void main(String [] args) throws Exception {
ErrorHandler errorHandler = new ErrorHandler();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser parser = spf.newSAXParser();
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaSource",
args[0]);
try {
parser.parse(args[1], errorHandler);
} catch (SAXException e) {
exit(1, "Fatal Error: " + e);
}
if (errorHandler.errorCounter == 0) {
exit(1, "Failed: " + args[1]
+ " is valid, but expected to violate identity constraint");
} else {
exit(0, "Passed.");
}
}
public static void exit(int errCode, String msg) {
System.out.println(msg);
System.exit(errCode);
}
}
----------------------------------------------------
------------------------------------------------ log
$javac test.java && java -showversion test test.xsd test.xml java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b35)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b35, mixed mode)
Failed: test.xml is valid, but expected to violate identity constraint
----------------------------------------------------
======================================================================
Identity-constraint validation does not regard the field order.
The new JCK-15 beta2 test adopted from W3C XSTC-20020116 testsuite:
api/xml_schema/msxsdtest/identityConstraint/idH012.html#idH012_i
declares a key and a keyref. The keyref's fields are the same that of the referenced
key, but have different order. When the instance document is validated,
fields of the key are evaluated to the the following key-sequence: (1, a),
Fields of the keyref are evaluated to the the following key-sequence: (a, 1).
Those key sequences are not equal and there is no other key
in the context of the keyref. So the rule 4.3 of the Validation Rule: Identity-constraint
Satisfied (see the XML Schema Structures, Section 3.11.6 Constraints on Identity-constraint
Definition Schema Components) is violated in the test instance document but the RI does not
report any error.
The bug is found in jdk1.5.0/beta/b35.
To reproduce the bug compile and run the following code as shown in the log below.
------------------------------------------- test.xml
<?xml version="1.0"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<kid val="1" val2="a"/>
<uid val2="a" val="1"/>
</root>
----------------------------------------------------
------------------------------------------- test.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="kid" maxOccurs="unbounded"/>
<xsd:element ref="uid" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:keyref name="kruid" refer="kuid">
<xsd:selector xpath=".//uid"/>
<xsd:field xpath="@val"/>
<xsd:field xpath="@val2"/>
</xsd:keyref>
<xsd:key name="kuid">
<xsd:selector xpath=".//kid"/>
<xsd:field xpath="@val2"/>
<xsd:field xpath="@val"/>
</xsd:key>
</xsd:element>
<xsd:element name="uid">
<xsd:complexType>
<xsd:attribute name="val" type="xsd:string"/>
<xsd:attribute name="val2" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="kid">
<xsd:complexType>
<xsd:attribute name="val" type="xsd:string"/>
<xsd:attribute name="val2" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
----------------------------------------------------
------------------------------------------ test.java
import java.io.File;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
public class test {
protected static class ErrorHandler extends DefaultHandler {
public int errorCounter = 0;
public void error(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
public void fatalError(SAXParseException e) throws SAXException {
System.out.println(e);
errorCounter++;
}
}
public static void main(String [] args) throws Exception {
ErrorHandler errorHandler = new ErrorHandler();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser parser = spf.newSAXParser();
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaSource",
args[0]);
try {
parser.parse(args[1], errorHandler);
} catch (SAXException e) {
exit(1, "Fatal Error: " + e);
}
if (errorHandler.errorCounter == 0) {
exit(1, "Failed: " + args[1]
+ " is valid, but expected to violate identity constraint");
} else {
exit(0, "Passed.");
}
}
public static void exit(int errCode, String msg) {
System.out.println(msg);
System.exit(errCode);
}
}
----------------------------------------------------
------------------------------------------------ log
$javac test.java && java -showversion test test.xsd test.xml java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b35)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b35, mixed mode)
Failed: test.xml is valid, but expected to violate identity constraint
----------------------------------------------------
======================================================================