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

Document.importNode() throws NullPointerException for DocumentType node

    XMLWordPrintable

Details

    • 1.3
    • generic
    • generic

    Backports

      Description

        Name: erR10175 Date: 05/17/2004



             The following method of the default org.w3c.dom.Document interface implementation

        Node importNode(Node importedNode, boolean deep)

        throws NullPointerException when a DocumentType node is imported.

        The documentation of the method reads:

        "
        The following list describes the specifics for each type of node.
        ...
        DOCUMENT_TYPE_NODE
            DocumentType nodes cannot be imported.
        ...
        Throws:
            DOMException - NOT_SUPPORTED_ERR: Raised if the type of node being imported
                           is not supported.
        "

        So, in the test (see below) NOT_SUPPORTED_ERR DOMException is expected
        instead of NullPointerException.

        This bug affects new test in JCK 1.5
            api/org_w3c/dom/Document/index.html#ImportNode[ImportNode005]

        The bug is found in jdk1.5.0/beta/b51 and is not reproducible in jdk1.5.0/beta/b50.

        To reproduce the bug compile and run test.java as shown in the log below:
        ------------------------------------------ test.java
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.DocumentBuilder;
        import org.w3c.dom.DocumentType;
        import org.w3c.dom.Document;
        import org.w3c.dom.DOMException;

        class test {
            public static void main(String [] args) throws Exception {
                DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().
                                         newDocumentBuilder();
                Document document1 = docBuilder.newDocument();
                Document document2 = docBuilder.newDocument();

                DocumentType docType = document1.getImplementation()
                                      .createDocumentType("root", null, null);

                try {
                    document2.importNode(docType, false);
                    System.out.println("Failed: document type node imported,"
                                     + " no exception is thrown.");
                } catch (DOMException e) {
                    int code = ((DOMException)e).code;
                    if (DOMException.NOT_SUPPORTED_ERR == code) {
                        System.out.println("Passed.");
                    } else {
                        System.out.println("Failed: Unexpected error code "
                                         + code);
                    }
                }
            }
        }
        ----------------------------------------------------

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

        Exception in thread "main" java.lang.NullPointerException
                at com.sun.org.apache.xerces.internal.dom.NodeImpl.getUserDataRecord(NodeImpl.java:1836)
                at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1477)
                at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1444)
                at test.main(test.java:18)
        ----------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: