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

Adopting attribute node causes NullPointerException

XMLWordPrintable

    • b30
    • generic
    • generic
    • Verified

        Name: eaR10174 Date: 09/01/2003


          The method Document.adoptNode() throws NullPointerException in case when an attribute
        node is adopted (see test.java below).
          
          The bug appears in jdk1.5.0beta-b17 and affects a new JCK1.5 test:
          
            api/org_w3c/dom/Document/index.html#AdoptNode[AdoptNode007]

        ------------------------------------test.java-----------------------------
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.DocumentBuilder;
        import org.w3c.dom.Document;
        import org.w3c.dom.Attr;

        public class test {

            public static void main(String argv[]) {
                new test().run();
            }
            
            public void run() {
                try {
                    DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
                    
                    Document doc1 = docBF.newDocumentBuilder().newDocument();
                    Document doc2 = docBF.newDocumentBuilder().newDocument();
                    
                    Attr attr1 = doc1.createAttribute("attr1");
                    Attr attr2 = (Attr)doc2.adoptNode(attr1);
                    
                    System.out.println("OK");
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }

            }
        }
        --------------------------------------------------------------------------
        % 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)

        java.lang.NullPointerException
                at
        com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.adoptNode(CoreDocumentImpl.java:16
        17)
                at test.run(test.java:20)
                at test.main(test.java:9)
        --------------------------------------------------------------------------

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

              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: