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

HTMLDocument.getElement() returns incorrect value

XMLWordPrintable



      Name: ooR10001 Date: 07/02/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(magicid).getName());
        }

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

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

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

      % java test

      content

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

      According to current JavaDoc correct result should be "ADDRESS".

      JavaDoc says:

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

      public Element getElement(String id)

            Returns the element that has the given id Attribute. If the element can't
            be found, null is returned. Note that this method works on an Attribute,
            not a character tag. In the following HTML snippet: <a id="HelloThere">
            the attribute is 'id' and the character tag is 'a'. This is a convenience
            method for getElement(RootElement, HTML.Attribute.id, id). This is not
            thread-safe.

            Parameters:
                  id - the string representing the desired Attribute
            Returns:
                  the element with the specified Attribute or null if it can't be
                  found, or null if id is null
            Since:
                  1.3
            See Also:
                  HTML.Attribute

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

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

            svioletsunw Scott Violet (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: