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

HTMLEditorKit.read() throws EmptyStackException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.2.2, 1.3.0, 1.3.1
    • client-libs
    • merlin
    • generic, x86
    • generic, linux, windows_nt

      Name: skT88420 Date: 10/12/99


      If an html page ending in </html><p> is read by
      HTMLEditorKit.read() an EmptyStackException is thrown.

      The problem can be reproduced by compiling the following test
      program:

      TestHTMLRead.java:
      public class TestHTMLRead extends javax.swing.JFrame
      {
      // To replicate the EmptyStackException, set the URL to any html page
      // which has something (e.g., <p>) after the </html> tag. A real world
      // example of pages ending with </hmtl><p> can be found by going to
      // www.amazon.com, select Books link, and then select any subject link,
      // such as History or Travel.
      //
          public TestHTMLRead()
          {
              try {
                  String url = "file:///javaBugs/EmptyStackException/readme.html";
                  getContentPane().add(java.awt.BorderLayout.CENTER, new javax.swing.JEditorPane(url));
                  setSize(600, 400);
              } catch (java.io.IOException ex) { ex.printStackTrace(); }
          }

          public static void main(String[] argv)
          {
              (new TestHTMLRead()).show();
          }
      }

      The 'readme.html' file used in my test is below. I created it
      by simply adding <p> to the end of the 1.3Beta readme.html file
      and then deleting the bulk of the page. In doing this I found
      a SECOND BUG, which is more serious than the first. I found
      that if I deleted anymore than what I did, the HTML tags were
      ignored and the result was just unformatted text. PLEASE TEST
      THIS SECOND BUG by deleting any line in the readme.html file,
      such as the Contents header, and rerun the test program.

      readme.html:
      <html><head>
      <title>HTML page that causes EmptyStackException on HTMLEditorKit.read()</title>
      </head>
      <body bgcolor="#ffffff">
      <center>
      <h1>Reading this page causes EmptyStackException using</h1>
      <h3>Java<sup><font size=-2>TM</font></sup> 2 SDK, Standard Edition<br>
      Version 1.3 Beta</h3>
      </center>
      <h2>Contents</h2>
      <p>
      <h2>Bug Reports and Feedback</h2>
      <h2>Sun Java Web Pages</h2>
      <blockquote>
      For additional information, refer to these Sun Microsystems pages on the
      World Wide Web:
      <dl>
          <dt><a href=http://java.sun.com/&gt;http://java.sun.com/&lt;/a>
          <dd>The Java Software web site, with the latest information on
      Java technology, product information, news, and features.

          <dt><a href=http://developer.java.sun.com/&gt;http://developer.java.sun.com/&lt;/a>
          <dd>The Java Developer Connection web site.

          <dt><a href=http://java.sun.com/products/&gt;http://java.sun.com/products/&lt;/a>
          <dd>Java Technology Products & API

          <dt><a href=http://www.sun.com/solaris/java/&gt;http://www.sun.com/solaris/java/&lt;/a>
          <dd>Java 2 SDK for Solaris - Production Release
      </dl>
      </blockquote>
      <p>
      <hr>
      </body></html><p>


      The Trace for the exception:
      C:\javaBugs\EmptyStackException>java TestHTMLRead
      java.util.EmptyStackException
              at java.util.Stack.peek(Unknown Source)
              at javax.swing.text.DefaultStyledDocument$ElementBuffer.insertElement(Unknown Source)
              at javax.swing.text.DefaultStyledDocument$ElementBuffer.create(Unknown Source)
              at javax.swing.text.DefaultStyledDocument.create(Unknown Source)
              at javax.swing.text.html.HTMLDocument.create(Unknown Source)
              at javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(Unknown Source)
              at javax.swing.text.html.HTMLDocument$HTMLReader.flush(Unknown Source)
              at javax.swing.text.html.HTMLEditorKit.read(Unknown Source)
              at javax.swing.JEditorPane.read(Unknown Source)
              at javax.swing.JEditorPane$PageLoader.run(Unknown Source)

      C:\javaBugs\EmptyStackException>java -version
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)

      This problem is not new with JDK 1.3Beta. I first encountered it
      with JDK1.2.2 and only tested JDK1.3Beta before submitting a bug
      report.
      (Review ID: 96461)
      ======================================================================

      Name: rlT66838 Date: 11/19/99


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-001, green threads, sunwjit)

      AND ALSO

      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)

      AS WELL AS

      jdk1.2.2 & HotSpot (latest to date) on WinNT



      HTMLEditorKit crashes when the html code it should parse contains the ^@ (char
      code 0, I believe) character.

          StringReader reader = new StringReader(textToParse);
          EditorKit kit = new HTMLEditorKit();
          doc = kit.createDefaultDocument();

          // The Document class does not yet handle charset's properly.
          doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

          try {
            kit.read(reader, doc, 0);
          }
          catch (BadLocationException e) {}
          catch (IOException e) {}
        }

      greats me with the following stack trace:

      Exception in thread "main" java.util.EmptyStackException
              at java.util.Stack.peek(Stack.java, Compiled Code)
              at
      javax.swing.text.DefaultStyledDocument$ElementBuffer.insertElement(DefaultStyled
      Document.java, Compiled Code)
              at
      javax.swing.text.DefaultStyledDocument$ElementBuffer.insertUpdate(DefaultStyledD
      ocument.java, Compiled Code)
              at
      javax.swing.text.DefaultStyledDocument$ElementBuffer.insert(DefaultStyledDocumen
      t.java, Compiled Code)
              at
      javax.swing.text.DefaultStyledDocument.insert(DefaultStyledDocument.java,
      Compiled Code)
              at javax.swing.text.html.HTMLDocument.insert(HTMLDocument.java, Compiled
      Code)
              at
      javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(HTMLDocument.java,
      Compiled Code)
              at
      javax.swing.text.html.HTMLDocument$HTMLReader.flush(HTMLDocument.java, Compiled
      Code)
              at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java, Compiled
      Code)
      (Review ID: 98074)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: