Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4964201

normalizeDocument() throws NPE if 'datatype-normalization' is set to true

    Details

    • Subcomponent:
    • Resolved In Build:
      b32
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Name: erR10175 Date: 12/05/2003


       
        The method org.w3c.dom.Document.normalizeDocument() throws NullPointerException
      if a simple xml document is validated by XML Schema and 'datatype-normalization'
      is set to true.

      The method description does not specify any exception.

      This bug affects new tests in JCK 1.5 (not integrated yet)
         api/org_w3c/dom/DOMConfiguration/index.html#Params[DatatypeNormalization001]

      The bug is found in jdk1.5.0/beta/b30.

      To reproduce the bug place test.java, test.xml and test.xsd to your current directory,
      then compile and run test.java as shown in the log below:
      ------------------------------ test.java
      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 final String SCHEMA_LANGUAGE
              = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
          static final String SCHEMA_SOURCE
              = "http://java.sun.com/xml/jaxp/properties/schemaSource";

          static Document loadDocument(String schemaFile, String instanceFile)
                                              throws Exception {
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              if (schemaFile != null) {
                  dbf.setNamespaceAware(true);
                  dbf.setValidating(true);
                  dbf.setAttribute(SCHEMA_LANGUAGE
                      , XMLConstants.W3C_XML_SCHEMA_NS_URI);
                  dbf.setAttribute(SCHEMA_SOURCE, schemaFile);
              }
              return dbf.newDocumentBuilder().parse(instanceFile);
          }

          public static void main(String [] args) throws Exception {
              Document doc = loadDocument("test.xsd", "test.xml");
              DOMConfiguration config = doc.getDomConfig();
              config.setParameter("validate", Boolean.TRUE);
              Element root = doc.getDocumentElement();

              System.out.println("normalizing with 'datatype-normalization' set to "
                  + config.getParameter("datatype-normalization") + " ...");
              doc.normalizeDocument();
              System.out.println("OK");

              config.setParameter("datatype-normalization", Boolean.TRUE);

              System.out.println("normalizing with 'datatype-normalization' set to "
                  + config.getParameter("datatype-normalization") + " ...");
              doc.normalizeDocument();
              System.out.println("OK");
          }
      }
      ----------------------------------------------------

      ------------------------------------------- test.xsd
      <?xml version="1.0"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  targetNamespace="test">
          <xsd:element name="root"/>
      </xsd:schema>
      ----------------------------------------------------

      ------------------------------------------- test.xml
      <?xml version="1.0"?>
      <test:root xmlns:test="test"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="test test.xsd"
      />
      ----------------------------------------------------

      ------------------------------------------------ log
      $javac test.java && java -cp . -showversion testjava version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b30)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b30, mixed mode)

      normalizing with 'datatype-normalization' set to false ...
      OK
      normalizing with 'datatype-normalization' set to true ...
      Exception in thread "main" java.lang.NullPointerException
              at com.sun.org.apache.xerces.internal.dom.AttrNSImpl.checkNSBinding(AttrNSImpl.java:374)
              at com.sun.org.apache.xerces.internal.dom.AttrNSImpl.setValue(AttrNSImpl.java:367)
              at com.sun.org.apache.xerces.internal.dom.DOMNormalizer.startElement(DOMNormalizer.java:1548)
              at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:693)
              at com.sun.org.apache.xerces.internal.dom.DOMNormalizer.normalizeNode(DOMNormalizer.java:433)
              at com.sun.org.apache.xerces.internal.dom.DOMNormalizer.normalizeDocument(DOMNormalizer.java:256)
              at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.normalizeDocument(CoreDocumentImpl.java:1075)
              at test.main(test.java:42)
      ----------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              vkorcl Venugopal K (Inactive)
              Reporter:
              reysunw Rey Rey (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: