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

Attr.getSpecified() returns true for attribute with default value

    Details

      Description



      Name: inR10064 Date: 11/04/2000


        Invocation of the getSpecified() method defined in interface org.w3c.dom.Attr
      doesn't return false when the Attr object has no value explicitly assigned
      in the document, but has a default value defined in DTD (See test.java below) .
                                                        
        Definition in p. 1.2 "Fundamental Interfaces" of DOM Level 2 Core
      (http://www.w3.org/TR/2000/PR-DOM-Level-2-Core-20000927/core.html#ID-637646024)
      says:

      " Attributes
            |specified| of type boolean, readonly
                 .......
                 If the attribute has no assigned value in the document and has a default
                 value in the DTD, then specified is false, and the value is the default
                 value in the DTD. "

      This bug presents in builds jaxp-1.1ea-b8, jaxp-1.1fcs-b9 and jaxp-1.1ea2-b10
      and affects the test in TCK JAXP 1.1

      api/com/sun/xml/tests/dom/AttributeTest.html#positiveGetSpecifiedFalse

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

      public class test {
          
          public static void main(String argv[]) {
              
              try {
                  DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance()
                                                    .newDocumentBuilder();

                  String data =
                      "<?xml version=\"1.0\" ?>" +
                      "<!DOCTYPE root [" +
                      "<!ELEMENT root ANY>" +
                      "<!ATTLIST root c CDATA #FIXED \"xxx\">" +
                      "]>" +
                      "<root/>";
              
                  ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());

                  Document document = documentBuilder.parse(in);
                  
                  Element root = document.getDocumentElement();
                  
                  Attr attr = root.getAttributeNode("c");
                  
                  System.out.println("Attr implementation: " + attr.getClass().getName());
                  
                  System.out.println("specified: " + attr.getSpecified());
                  
              } catch (Exception e) {
                  System.out.println("Unexpected " + e + " was thrown");
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % java -showversion -cp .:jaxp1.1/jaxp.jar:jaxp1.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)

      Attr implementation: org.apache.crimson.tree.AttributeNode
      specified: true

      % java -showversion -cp .:jaxp1.0.1/jaxp.jar:jaxp1.0.1/parser.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)

      Attr implementation: com.sun.xml.tree.AttributeNode
      specified: false
      ---------------------------------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                egoei Edwin Goei (Inactive)
                Reporter:
                inevsunw Inev Inev (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: