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

HTMLDocument.getElement() returns incorrect value

XMLWordPrintable

    • tiger
    • sparc
    • solaris_2.6, solaris_7



      Name: ooR10001 Date: 07/19/2001


      javax.swing.text.html.HTMLDocument.getElement() returns incorrect value.
      Following test shows a bug:

      ----------- test.java -------------
      import javax.swing.text.html.HTMLDocument;
      import javax.swing.text.html.HTMLEditorKit;
      import java.io.StringReader;

      public class test {

        public static void main(String[] args) {
            String magic="MAGIC_STRING1234567890";
            String magicid="magicid";
            String test="<!DOCTYPE HTML PUBLIC \"-//w3c//DTD html 3.2//EN\">"
                    + "<HTML><TITLE>test</TITLE>"
                    + "<BODY><ADDRESS id=\""+magicid+"\">"
                    + magic +"</ADDRESS></BODY></HTML>";
                  
          HTMLEditorKit c = new HTMLEditorKit();
          HTMLDocument doc = null;
          
          try {
              doc = new HTMLDocument();
              c.read(new StringReader(test),doc,0);
          } catch(Exception e) {
              System.out.println("Exception thrown.");
              return;
          }
          System.out.println(doc.getElement(doc.getDefaultRootElement(),
                             HTML.Attribute.ID, magicid));
        }

      }
      -----------------------------------

      Output:
      -----------------------------
      % java -version

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

      % java test

      null

      -----------------------------

      According to current JavaDoc correct result should not be null.

      JavaDoc says:

      ------------------------------
      getElement

      public Element getElement(Element e,
                                Object attribute,
                                Object value)

            Returns the child element of e that contains the attribute, attribute with
      value value, or null if
            one isn't found. This is not thread-safe.

            Parameters:
                  e - the root element where the search begins
                  attribute - the desired Attribute
                  value - the values for the specified Attribute
            Returns:
                  the element with the specified Attribute and the specified value,
                  or null if it can't be found
            Since:
                  1.3
            See Also:
                  HTML.Attribute
      ------------------------------

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

            idk Igor Kushnirskiy (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: