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

Methods setIdAttribute(), setIdAttributeNS() throw NullPointerException

    XMLWordPrintable

    Details

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

      Description

      Name: eaR10174 Date: 09/04/2003


        The methods Element.setIdAttribute(), Element.setIdAttributeNS() throw
      NullPointerException in case when the parameter name does not match any name of element
      attributes (see test.java below). According to the methods javadoc
        
           public void setIdAttribute(String name,
                                 boolean isId)
                          throws DOMException
                          
            ...
                          
            Throws:
             DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
             NOT_FOUND_ERR: Raised if the specified node is not an attribute of this element.


           public void setIdAttributeNS(String namespaceURI,
                                   String localName,
                                   boolean isId)
                            throws DOMException
                            
            ...

            Throws:
             DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
             NOT_FOUND_ERR: Raised if the specified node is not an attribute of this element.

      the methods should throw DOMException with the error code NOT_FOUND_ERR.

        The bug appears in jdk1.5.0beta-b18 and affects new JCK1.5 tests:
        
            api/org_w3c/dom/Element/index.html#SetIdAttribute[SetIdAttribute004]
            api/org_w3c/dom/Element/index.html#SetIdAttribute[SetIdAttributeNS004]

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

      public class test {

          public static void main(String argv[]) {
              test t = new test();
              t.run1();
              t.run2();
          }
          
          public void run1() {
              System.out.println();
              System.out.println("Testing setIdAttribute...");
              try {
                  Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                                .newDocument();
                  
                  Element elm = doc.createElement("root");
                  elm.setAttribute("a", "01");

                  elm.setIdAttribute("b", true);
                  
              } catch (Exception e) {
                  e.printStackTrace();
                  return;
              }

          }
          
          public void run2() {
              System.out.println();
              System.out.println("Testing setIdAttributeNS...");
              try {
                  DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
                  docBF.setNamespaceAware(true);
                  Document doc = docBF.newDocumentBuilder().newDocument();
                  
                  Element elm = doc.createElementNS("ns1", "ns:root");
                  elm.setAttributeNS("ns1", "ns:a", "01");

                  elm.setIdAttributeNS("ns1", "ns:b", true);
                  
              } 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-b18)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b18, mixed mode)

      Testing setIdAttribute...
      java.lang.NullPointerException
              at
      com.sun.org.apache.xerces.internal.dom.ElementImpl.setIdAttribute(ElementImpl.java:953)
              at test.run1(test.java:24)
              at test.main(test.java:10)

      Testing setIdAttributeNS...
      java.lang.NullPointerException
              at
      com.sun.org.apache.xerces.internal.dom.ElementImpl.setIdAttributeNS(ElementImpl.java:985)
              at test.run2(test.java:44)
              at test.main(test.java:11)
      --------------------------------------------------------------------------

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

        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: