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

adoptNode() accepts Notation, Entity nodes without errors

XMLWordPrintable

    • b30
    • generic
    • generic
    • Verified

        Name: eaR10174 Date: 09/02/2003


          The method Document.adoptNode() throws no exceptions and returns non-null value in case
        when Notation, Entity nodes are used as argument (see test.java below). According to the
        method javadoc
          
          public Node adoptNode(Node source)
                       throws DOMException
                       
               ...
               ENTITY_NODE
                  Entity nodes cannot be adopted.
                  
               NOTATION_NODE
                  Notation nodes cannot be adopted.


        the method should not adopt nodes of these types. The method should either throw an
        exception or return null.

          The bug appears in jdk1.5.0beta-b17 and affects a new JCK1.5 test:
          
            api/org_w3c/dom/Document/index.html#AdoptNode[AdoptNode012]
            api/org_w3c/dom/Document/index.html#AdoptNode[AdoptNode017]

        ------------------------------------test.java-----------------------------
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.DocumentBuilder;
        import org.xml.sax.InputSource;
        import org.w3c.dom.Document;
        import org.w3c.dom.Node;
        import java.io.StringReader;

        public class test {

            String data =
                "<?xml version=\"1.0\" ?>"
                + "<!DOCTYPE root ["
                + "ELEMENT root ANY"
                + "ENTITY ent SYSTEM \"text.txt\""
                + "NOTATION notation PUBLIC \"http://xxx.xxx.xxx/\""
                + "]>"
                + "<root/>";
              
            DocumentBuilder docBuilder = null;

            public static void main(String argv[]) {
                new test().run();
            }
            
            public void run() {
                try {
                    DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
                    docBuilder = docBF.newDocumentBuilder();
                    
                    Document doc1 = parse(data);
                    Document doc2 = docBuilder.newDocument();
                    
                    Node notation = doc1.getDoctype().getNotations().getNamedItem("notation") ;
                    Node entity = doc1.getDoctype().getEntities().getNamedItem("ent");
                    
                    Node node1 = doc2.adoptNode(notation);
                    Node node2 = doc2.adoptNode(entity);
                    
                    if (node1 != null) {
                        System.out.println("Adopting notation: non-null returned");
                    }
                    
                    if (node2 != null) {
                        System.out.println("Adopting entity: non-null returned");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }

            }
            
            private Document parse(String xmlData) throws Exception {
                 StringReader in = new StringReader(xmlData);
                 InputSource source = new InputSource(in);
                 return docBuilder.parse(source);
            }
        }
        --------------------------------------------------------------------------
        % java -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b17)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b17, mixed mode)

        Adopting notation: non-null returned
        Adopting entity: non-null returned
        --------------------------------------------------------------------------

        ======================================================================
        ###@###.### 2003-09-03

              nbajajsunw Neeraj Bajaj (Inactive)
              evgsunw Evg Evg (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: