-
Bug
-
Resolution: Fixed
-
P3
-
1.0.2
-
1.2beta4
-
sparc
-
solaris_2.5.1
-
Not verified
If Document.remove() is called before calling HTMLEditorKit.read(), an
EmptyStackException is thrown.
Platform: Solaris 2.5.1, JDK 1.1.6, Swing 1.0.2
The stack trace is:
Exception occurred during event dispatching:
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java)
at com.sun.java.swing.text.DefaultStyledDocument$ElementBuffer.insertElement(DefaultStyledDocument.java:1096)
at com.sun.java.swing.text.DefaultStyledDocument$ElementBuffer.insertUpdate(DefaultStyledDocument.java:879)
at com.sun.java.swing.text.DefaultStyledDocument$ElementBuffer.insert(DefaultStyledDocument.java:826)
at com.sun.java.swing.text.DefaultStyledDocument.insert(DefaultStyledDocument.java:141)
at com.sun.java.swing.text.html.HTMLDocument.insert(HTMLDocument.java:96)
at com.sun.java.swing.text.html.HTMLDocument$HTMLReader.flush(HTMLDocument.java:172)
at com.sun.java.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:123)
at com.sun.java.swing.text.DefaultEditorKit.read(DefaultEditorKit.java:122)
at EditorPaneTest.actionPerformed(EditorPaneTest.java:57)
at com.sun.java.swing.AbstractButton.fireActionPerformed(AbstractButton.java:861)
at com.sun.java.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:896)
at com.sun.java.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:338)
at com.sun.java.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:230)
at com.sun.java.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:159)
at java.awt.Component.processMouseEvent(Component.java:2404)
at java.awt.Component.processEvent(Component.java:2249)
at java.awt.Container.processEvent(Container.java:878)
at java.awt.Component.dispatchEventImpl(Component.java:1781)
at java.awt.Container.dispatchEventImpl(Container.java:923)
at java.awt.Component.dispatchEvent(Component.java:1708)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1559)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1463)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1395)
at java.awt.Container.dispatchEventImpl(Container.java:910)
at java.awt.Window.dispatchEventImpl(Window.java:492)
at java.awt.Component.dispatchEvent(Component.java:1708)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:81)
Reproduce by compiling and running the following sample program:
/*
* This sample program demonstrates a problem in the HTMLEditorKit.
* If a Document's contents are removed and then a subsequent call
* to the read method of HTMLEditorKit is made, an EmptyStackException
* is thrown.
*
* To Reproduce:
*
* - Compile and run the following program.
* - A web page will be displayed (you'll need to resize it to see it all)
* - Then click on the "Load New Document" button to try to read in a new
* web page. This will fail with an EmptyStackException.
*/
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.text.html.*;
import com.sun.java.swing.event.*;
public class EditorPaneTest extends JFrame implements ActionListener,
DocumentListener {
JEditorPane editor;
Document doc;
public EditorPaneTest() {
JButton button;
try {
editor = new JEditorPane("http://icdev.eng/~cecilia/cecilia.html");
doc = editor.getDocument();
doc.addDocumentListener(this);
button = new JButton("Load New Document");
button.addActionListener(this);
getContentPane().add(BorderLayout.CENTER, editor);
getContentPane().add(BorderLayout.SOUTH, button);
} catch (IOException e) {
}
}
public void actionPerformed(ActionEvent e) {
InputStream in = null;
HTMLEditorKit kit = new HTMLEditorKit();
// Read in new document
try {
doc.removeDocumentListener(this);
doc.remove(0, doc.getLength());
URL url = new URL("http://icdev.eng/~cecilia/wonderland.html");
in = url.openStream();
kit.read(in, doc, 0);
} catch (MalformedURLException err) {
} catch (IOException err) {
} catch (BadLocationException err) {
} finally {
doc.addDocumentListener(this);
try {
if (in != null) in.close();
} catch (IOException err) {
}
}
}
public void changedUpdate(DocumentEvent e) {
System.out.println("HtmlEditor: changedUpdate called");
}
public void insertUpdate(DocumentEvent e) {
System.out.println("HtmlEditor: insertUpdate called");
}
public void removeUpdate(DocumentEvent e) {
System.out.println("HtmlEditor: removeUpdate called");
}
public static void main(String[] argv) {
EditorPaneTest ept = new EditorPaneTest();
ept.pack();
ept.show();
}
}
EmptyStackException is thrown.
Platform: Solaris 2.5.1, JDK 1.1.6, Swing 1.0.2
The stack trace is:
Exception occurred during event dispatching:
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java)
at com.sun.java.swing.text.DefaultStyledDocument$ElementBuffer.insertElement(DefaultStyledDocument.java:1096)
at com.sun.java.swing.text.DefaultStyledDocument$ElementBuffer.insertUpdate(DefaultStyledDocument.java:879)
at com.sun.java.swing.text.DefaultStyledDocument$ElementBuffer.insert(DefaultStyledDocument.java:826)
at com.sun.java.swing.text.DefaultStyledDocument.insert(DefaultStyledDocument.java:141)
at com.sun.java.swing.text.html.HTMLDocument.insert(HTMLDocument.java:96)
at com.sun.java.swing.text.html.HTMLDocument$HTMLReader.flush(HTMLDocument.java:172)
at com.sun.java.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:123)
at com.sun.java.swing.text.DefaultEditorKit.read(DefaultEditorKit.java:122)
at EditorPaneTest.actionPerformed(EditorPaneTest.java:57)
at com.sun.java.swing.AbstractButton.fireActionPerformed(AbstractButton.java:861)
at com.sun.java.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:896)
at com.sun.java.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:338)
at com.sun.java.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:230)
at com.sun.java.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:159)
at java.awt.Component.processMouseEvent(Component.java:2404)
at java.awt.Component.processEvent(Component.java:2249)
at java.awt.Container.processEvent(Container.java:878)
at java.awt.Component.dispatchEventImpl(Component.java:1781)
at java.awt.Container.dispatchEventImpl(Container.java:923)
at java.awt.Component.dispatchEvent(Component.java:1708)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:1559)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1463)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1395)
at java.awt.Container.dispatchEventImpl(Container.java:910)
at java.awt.Window.dispatchEventImpl(Window.java:492)
at java.awt.Component.dispatchEvent(Component.java:1708)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:81)
Reproduce by compiling and running the following sample program:
/*
* This sample program demonstrates a problem in the HTMLEditorKit.
* If a Document's contents are removed and then a subsequent call
* to the read method of HTMLEditorKit is made, an EmptyStackException
* is thrown.
*
* To Reproduce:
*
* - Compile and run the following program.
* - A web page will be displayed (you'll need to resize it to see it all)
* - Then click on the "Load New Document" button to try to read in a new
* web page. This will fail with an EmptyStackException.
*/
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.text.html.*;
import com.sun.java.swing.event.*;
public class EditorPaneTest extends JFrame implements ActionListener,
DocumentListener {
JEditorPane editor;
Document doc;
public EditorPaneTest() {
JButton button;
try {
editor = new JEditorPane("http://icdev.eng/~cecilia/cecilia.html");
doc = editor.getDocument();
doc.addDocumentListener(this);
button = new JButton("Load New Document");
button.addActionListener(this);
getContentPane().add(BorderLayout.CENTER, editor);
getContentPane().add(BorderLayout.SOUTH, button);
} catch (IOException e) {
}
}
public void actionPerformed(ActionEvent e) {
InputStream in = null;
HTMLEditorKit kit = new HTMLEditorKit();
// Read in new document
try {
doc.removeDocumentListener(this);
doc.remove(0, doc.getLength());
URL url = new URL("http://icdev.eng/~cecilia/wonderland.html");
in = url.openStream();
kit.read(in, doc, 0);
} catch (MalformedURLException err) {
} catch (IOException err) {
} catch (BadLocationException err) {
} finally {
doc.addDocumentListener(this);
try {
if (in != null) in.close();
} catch (IOException err) {
}
}
}
public void changedUpdate(DocumentEvent e) {
System.out.println("HtmlEditor: changedUpdate called");
}
public void insertUpdate(DocumentEvent e) {
System.out.println("HtmlEditor: insertUpdate called");
}
public void removeUpdate(DocumentEvent e) {
System.out.println("HtmlEditor: removeUpdate called");
}
public static void main(String[] argv) {
EditorPaneTest ept = new EditorPaneTest();
ept.pack();
ept.show();
}
}