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

method IIOMetadataNode.setAttributeNode does not work as described

    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

         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:
              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: