-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b51
-
generic
-
generic
-
Verified
Name: erR10175 Date: 05/04/2004
The following method in the class org.w3c.dom.Document
void normalizeDocument()
does not perform validation when the following DOMConfiguration properties are set:
schema-type, schema-location, validate, datatype-normalization, error-handler.
The javadoc of the DOMConfiguration class reads:
"
validate
true
[optional] Require the validation against a schema (i.e. XML schema, DTD, any other
type or representation of schema) of the document as it is being normalized
as defined by [XML 1.0]. If validation errors are found, or no schema was found,
the error handler is notified.
"
So the sample (see below) should catch an error when the string ' xxx ' is found in
the context where xsd:int is expected.
The bug is found in jdk1.5.0/beta2/b49 and is not reproducible with jdk1.5.0/beta2/b48.
The bug affects the following new JCK-15 beta2 tests:
api/org_w3c/dom/DOMConfiguration/index.html#Params[DatatypeNormalization001]
api/org_w3c/dom/DOMConfiguration/index.html#Params[Validate001]
To reproduce the bug compile and run the following code as shown in the log below.
---------------------------- test.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="test">
<xsd:element name="root" type="xsd:int"/>
</xsd:schema>
-------------------------------------
--------------------------- test.java
import org.w3c.dom.DOMError;
import org.w3c.dom.DOMErrorHandler;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.DOMConfiguration;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.XMLConstants;
class test {
static class TestHandler implements DOMErrorHandler {
String msg = "";
public boolean handleError(DOMError error) {
if (error.getSeverity() == DOMError.SEVERITY_ERROR
|| error.getSeverity() == DOMError.SEVERITY_FATAL_ERROR) {
msg += "; " + error.getMessage();
}
return true;
}
}
public static void main(String [] args) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
Document doc = dbf.newDocumentBuilder()
.getDOMImplementation()
.createDocument("test", "ns:root", null);
DOMConfiguration config = doc.getDomConfig();
config.setParameter("schema-type", XMLConstants.W3C_XML_SCHEMA_NS_URI);
config.setParameter("schema-location", "test.xsd");
config.setParameter("validate", Boolean.TRUE);
config.setParameter("datatype-normalization", Boolean.TRUE);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
Element root = doc.getDocumentElement();
root.appendChild(doc.createTextNode(" xxx ")); // invalid value
doc.normalizeDocument();
if (testHandler.msg.length() > 0) {
System.out.println("Passed with the following error(s): "
+ testHandler.msg.substring(2));
} else {
System.out.println("Failed: no error is reported for invalid content");
}
}
}
-------------------------------------
--------------------------------- log
$javac test.java && java -showversion test
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b49)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b49, mixed mode)
Failed: no error is reported for invalid content
-------------------------------------
======================================================================
Integrated into Tiger build 51 on May 9
###@###.### 2004-05-11
The following method in the class org.w3c.dom.Document
void normalizeDocument()
does not perform validation when the following DOMConfiguration properties are set:
schema-type, schema-location, validate, datatype-normalization, error-handler.
The javadoc of the DOMConfiguration class reads:
"
validate
true
[optional] Require the validation against a schema (i.e. XML schema, DTD, any other
type or representation of schema) of the document as it is being normalized
as defined by [XML 1.0]. If validation errors are found, or no schema was found,
the error handler is notified.
"
So the sample (see below) should catch an error when the string ' xxx ' is found in
the context where xsd:int is expected.
The bug is found in jdk1.5.0/beta2/b49 and is not reproducible with jdk1.5.0/beta2/b48.
The bug affects the following new JCK-15 beta2 tests:
api/org_w3c/dom/DOMConfiguration/index.html#Params[DatatypeNormalization001]
api/org_w3c/dom/DOMConfiguration/index.html#Params[Validate001]
To reproduce the bug compile and run the following code as shown in the log below.
---------------------------- test.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="test">
<xsd:element name="root" type="xsd:int"/>
</xsd:schema>
-------------------------------------
--------------------------- test.java
import org.w3c.dom.DOMError;
import org.w3c.dom.DOMErrorHandler;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.DOMConfiguration;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.XMLConstants;
class test {
static class TestHandler implements DOMErrorHandler {
String msg = "";
public boolean handleError(DOMError error) {
if (error.getSeverity() == DOMError.SEVERITY_ERROR
|| error.getSeverity() == DOMError.SEVERITY_FATAL_ERROR) {
msg += "; " + error.getMessage();
}
return true;
}
}
public static void main(String [] args) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
Document doc = dbf.newDocumentBuilder()
.getDOMImplementation()
.createDocument("test", "ns:root", null);
DOMConfiguration config = doc.getDomConfig();
config.setParameter("schema-type", XMLConstants.W3C_XML_SCHEMA_NS_URI);
config.setParameter("schema-location", "test.xsd");
config.setParameter("validate", Boolean.TRUE);
config.setParameter("datatype-normalization", Boolean.TRUE);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
Element root = doc.getDocumentElement();
root.appendChild(doc.createTextNode(" xxx ")); // invalid value
doc.normalizeDocument();
if (testHandler.msg.length() > 0) {
System.out.println("Passed with the following error(s): "
+ testHandler.msg.substring(2));
} else {
System.out.println("Failed: no error is reported for invalid content");
}
}
}
-------------------------------------
--------------------------------- log
$javac test.java && java -showversion test
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b49)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b49, mixed mode)
Failed: no error is reported for invalid content
-------------------------------------
======================================================================
Integrated into Tiger build 51 on May 9
###@###.### 2004-05-11