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

Bugs in method IIOMetadataNode.setAttributeNode

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      tiger
    • CPU:
      generic, x86
    • OS:
      generic, linux, windows_98
    • Verification:
      Verified

      Description

      Problem 1:

      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

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

      Problem 2:

      Name: ipR10067 Date: 09/26/2001



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

      "public Attr setAttributeNode(Attr newAttr) throws DOMException
       ...
        Returns:
             If the newAttr attribute replaces an existing attribute, the
             replaced Attr node is returned, otherwise null is returned."

      However, the implementation (JDK 1.4.0beta3, build b80) of the method does not
      return proper result (neither replaced Attr nor null).

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

      To reproduce the bug run the following test:

      ------------ test.java ------------------------
      package test;

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

      public class test {

          public static void main(String argv[]) {
              test3();
              test4();
          }

          public static void test3() {

              Attr retAttr;

              System.out.print("Test 3: ");
        
              IIOMetadataNode parent = new IIOMetadataNode("parent");
              MyAttrNode attrNode = new MyAttrNode("name", "value");

              retAttr = parent.setAttributeNode(attrNode);

              if (retAttr != null) {
                 System.out.println("Failed! return value is not null");
                 return;
              }
              System.out.println("Passed");
          }

          public static void test4() {
          
              String name = "attr";
              String value = "old value";
              Attr retAttr;
              String actName;
              String actValue;

              System.out.print("Test 4: ");

              IIOMetadataNode parent = new IIOMetadataNode("parent");
              MyAttrNode attrNode1 = new MyAttrNode(name);
              MyAttrNode attrNode2 = new MyAttrNode(name);
              attrNode1.setValue(value);
              attrNode2.setValue("new value");
          
              retAttr = parent.setAttributeNode(attrNode1);
              retAttr = parent.setAttributeNode(attrNode2); // attrNode1 should be returned
              
              actName = retAttr.getNodeName();
              actValue = retAttr.getValue();
              if (! (actName.equals(name) && actValue.equals(value))) {
                 System.out.println("Failed! invalid attribute node returned " +
                         "(name: " + actName + ", value: " + actValue + ")");
                 return;
              }

              System.out.println("Passed");
          }

      }
       

      class MyAttrNode extends IIOMetadataNode implements Attr {
          public Element owner;
          private String name;
          private String value;

          public MyAttrNode(String name) {
              this.name = name;
          }

          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

      Test 3: Failed! return value is not null
      Test 4: Failed! invalid attribute node returned (name: attr, value: new value)

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

      Problem 3:

      Name: ipR10067 Date: 09/26/2001



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

      "public Attr setAttributeNode(Attr newAttr) throws DOMException

         Adds a new attribute node. If an attribute with that name (nodeName)
         is already present in the element, it is replaced by the new one.
         ..."

      However, the implementation (JDK 1.4.0beta3, build b80) of
      the method does not work as described. The present attribute with the same name
      is not replaced by the new one.

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

      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[]) {

              String name = "name";
              String value = "right value";
              Attr actAttr;
              String actValue;
          
              IIOMetadataNode parent = new IIOMetadataNode("parent");
              MyAttrNode attrNode1 = new MyAttrNode(name);
              MyAttrNode attrNode2 = new MyAttrNode(name);

              attrNode1.setValue("wrong value");
              attrNode2.setValue(value);

              parent.setAttributeNode(attrNode1);
              parent.setAttributeNode(attrNode2); // should replace attrNode1
              
              actAttr = parent.getAttributeNode(name);
              actValue = actAttr.getValue();
              if (! actValue.equals(value)) {
                 System.out.println("Failed! value is " + actValue);
                 return;
              }
              System.out.println("Passed");
          }

      }

      class MyAttrNode extends IIOMetadataNode implements Attr {
          public Element owner;
          private String name;
          private String value;

          public MyAttrNode(String name) {
              this.name = name;
          }

          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! value is wrong value

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: