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

Document.createAttribute() throws StringIndexOutOfBoundsException

    XMLWordPrintable

    Details

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

      Description



      Name: eaR10174 Date: 03/13/2001


        The implementation of method org.w3c.dom.Document.createAttribute(String name) throws
      StringIndexOutOfBoundsException when the argument is an empty string (See test.java below).

        Definition of the method in p. 1.2 "Fundamental Interfaces" of DOM Level 2 Core
      (http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document) doesn't forbid such cases:

        " createAttribute
                    Creates an Attr of the given name. Note that the Attr instance can then be set on an
                    Element using the setAttributeNode method. To create an attribute with a qualified name
                    and namespace URI, use the createAttributeNS method.
                    Parameters
                        name of type DOMString The name of the attribute.
                    Return Value
                        Attr A new Attr object with the nodeName attribute set to name, and localName,
                              prefix, and namespaceURI set to null. The value of the attribute is the empty
                              string.

                    Exceptions
                        DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal
                        character. "
                        
        This bug is found in the build jaxp-1.1.1-b23-10_mar_2001 and affects an old TCK test
        
        api/com/sun/xml/tests/dom/AttributeTest.html#negativeGetName

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

      public class test {
          
          public static void main(String argv[]) {
              try {
                  Document document = DocumentBuilderFactory.newInstance()
                                          .newDocumentBuilder().newDocument();
                                     
                  document.createAttribute("");
                  
                  System.out.println("Attribute created.");
              } catch (Exception e) {
                  System.out.println("Exception: " + e);
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % java -showversion -cp .:jaxp1.1.1/jaxp.jar:jaxp1.1.1/crimson.jar test
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

      Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      ---------------------------------------------------------------------------

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

        Attachments

          Activity

            People

            Assignee:
            egoei Edwin Goei (Inactive)
            Reporter:
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: