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

method IIOMetadataNode.setAttributeNode does not throw DOMException

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, linux, windows_98

      Description



      Name: ipR10067 Date: 09/26/2001



      Specification of the method
      javax.imageio.metadata.IIOMetadataNode.setAttributeNode says:

      "public Attr setAttributeNode(Attr newAttr) throws DOMException
       ...
       Specified by:
             setAttributeNode in interface Element
       ..."

      and specification of the method org.w3c.dom.Element.setAttributeNode says:

      "public Attr setAttributeNode(Attr newAttr) throws DOMException
       ...

       Throws:
         ...
             INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an attribute of
             another Element object.
         ..."


      However, the implementation (JDK 1.4.0beta3, build b80) of the method does not
      throw DOMException if newAttr is already an attribute of another Element object.


      This bug affects new JCK tests:
      api/javax_imageio/metadata/IIOMetadataNode/index.html#setAttributeNode[setAttributeNode001]
      api/javax_imageio/metadata/IIOMetadataNode/index.html#setAttributeNode[setAttributeNode005]

      To reproduce the bug run the following test:

      ------------ test.java ------------------------

      import javax.imageio.metadata.IIOMetadataNode;
      import org.w3c.dom.Attr;
      import org.w3c.dom.Element;

      public class test {

          public static void main(String argv[]) {

              IIOMetadataNode parent = new IIOMetadataNode("parent");
              IIOMetadataNode elem = new IIOMetadataNode("elem");

              MyAttrNode attrNode = new MyAttrNode("name", "value");
              elem.setAttributeNode(attrNode);
              attrNode.owner = elem;
          
              try {
                  parent.setAttributeNode(attrNode);
              } catch(org.w3c.dom.DOMException e) {
                  if (e.code != org.w3c.dom.DOMException.INUSE_ATTRIBUTE_ERR) {
                      System.out.println("Failed! Invalid exception code: " + e.code);
                      return;
                  }
                  System.out.println("Passed");
                  return;
              }
              System.out.println("Failed to throw DOMException");
          }

      }

      class MyAttrNode extends IIOMetadataNode implements Attr {
          public Element owner;
          private String name;
          private String value;
          
          public MyAttrNode(String name, String value) {
              this.name = name;
              this.value = value;
          }
          public String getName() {
              return name;
          }
          public Element getOwnerElement() {
              return owner;
          }
          public boolean getSpecified() {
              return false;
          }
          public String getValue() {
              return value;
          }
          public void setValue(String value) {
              this.value = value;
          }
      }
      ------------ Logs -----------------------------
      $ java -version

      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b80)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b80, mixed mode)

      $ javac test.java

      $ java test

      Failed to throw DOMException

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ipsunw Ip Ip (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: