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

Method adoptNode() throws ClassCastException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      6.0
    • CPU:
      generic
    • OS:
      generic

      Description

      Name: eaR10174 Date: 09/01/2003


        The method Document.adoptNode() throws ClassCastException in case when an element
      node of a parsed document 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[AdoptNode011]

      ------------------------------------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"
              + "ATTLIST root attr1 ID #FIXED 'xxx'"
              + " attr2 CDATA #IMPLIED "
              + "]>"
              + "<root attr2='yyy'/>";
            
          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 element = doc2.adoptNode(doc1.getDocumentElement());
                  
                  System.out.println("OK.");
              } 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)

      java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DocumentImpl
              at
      com.sun.org.apache.xerces.internal.dom.DeferredAttrImpl.synchronizeChildren(DeferredAttrIm
      pl.java:177)
              at
      com.sun.org.apache.xerces.internal.dom.AttrImpl.setOwnerDocument(AttrImpl.java:230)
              at
      com.sun.org.apache.xerces.internal.dom.NamedNodeMapImpl.setOwnerDocument(NamedNodeMapImpl.
      java:426)
              at
      com.sun.org.apache.xerces.internal.dom.ElementImpl.setOwnerDocument(ElementImpl.java:237)
              at
      com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.adoptNode(CoreDocumentImpl.java:16
      66)
              at test.run(test.java:33)
              at test.main(test.java:22)
      --------------------------------------------------------------------------

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

        Attachments

          Activity

            People

            Assignee:
            sreddysunw Sunitha Reddy (Inactive)
            Reporter:
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: