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

Document.renameNode() throws ArrayIndexOutOfBoundsException

    XMLWordPrintable

    Details

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

      Description

      Name: eaR10174 Date: 08/29/2003


        The method Document.renameNode() throws ArrayIndexOutOfBoundsException when an element
      node is renamed (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#RenameNode[RenameNode004]

      ------------------------------------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.Element;
      import org.w3c.dom.DocumentType;
      import java.io.StringReader;

      public class test {

          String data =
              "<!DOCTYPE root ["
              + "ELEMENT root EMPTY"
              + "ELEMENT elem1 EMPTY"
              + "ATTLIST elem1 attr1 CDATA #IMPLIED"
              + " attr2 CDATA 'changing1' "
              + "ELEMENT elem2 EMPTY"
              + "ATTLIST elem2 attr1 CDATA #IMPLIED"
              + " attr2 CDATA 'changing2' "
              + "]>"
              + "<root/>";

          DocumentBuilder docBuilder = null;

          public static void main(String argv[]) {
              new test().run();
          }
          
          public void run() {
              try {
                  DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
                  docBF.setNamespaceAware(true);
                  docBuilder = docBF.newDocumentBuilder();
                  
                  Document doc = parse(data);
                  
                  Element elem1 = doc.createElement("elem1");
                  elem1.setAttribute("attr1", "persistent");

                  Element elem2 = (Element) doc.renameNode(elem1, null, "elem2");
                  
                  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.ArrayIndexOutOfBoundsException: -2
              at java.util.Vector.setElementAt(Vector.java:492)
              at
      com.sun.org.apache.xerces.internal.dom.AttributeMap.reconcileDefaults(AttributeMap.java:59
      1)
              at
      com.sun.org.apache.xerces.internal.dom.ElementImpl.reconcileDefaultAttributes(ElementImpl.
      java:1086)
              at com.sun.org.apache.xerces.internal.dom.ElementImpl.rename(ElementImpl.java:137)
              at
      com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.renameNode(CoreDocumentImpl.java:8
      75)
              at test.run(test.java:40)
              at test.main(test.java:26)
      --------------------------------------------------------------------------

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

        Attachments

          Activity

            People

            Assignee:
            vkorcl Venugopal K (Inactive)
            Reporter:
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: