-
Bug
-
Resolution: Fixed
-
P4
-
1.4.2
-
b56
-
x86
-
windows_2000
Name: rmT116609 Date: 05/05/2004
FULL PRODUCT VERSION :
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
JEditorPane can throw an ArrayIndexOutOfBoundsException during layout when comment-containing HTML content is overwritten by other content. See the sample application. If you remove the comment from the HTML, the problem does not occur.
java.lang.ArrayIndexOutOfBoundsException: 0
at javax.swing.text.BoxView.getOffset(BoxView.java:1079)
at javax.swing.text.BoxView.childAllocation(BoxView.java:669)
at javax.swing.text.CompositeView.getChildAllocation(CompositeView.java:215)
at javax.swing.text.BoxView.getChildAllocation(BoxView.java:427)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(BasicTextUI.java:1856)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(BasicTextUI.java:1832)
at java.awt.Container.layout(Container.java:1020)
at java.awt.Container.doLayout(Container.java:1010)
at java.awt.Container.validateTree(Container.java:1092)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validate(Container.java:1067)
at java.awt.Window.show(Window.java:461)
at java.awt.Component.show(Component.java:1133)
at java.awt.Component.setVisible(Component.java:1088)
at JEditorPaneBug.demoBug(JEditorPaneBug.java:32)
at JEditorPaneBug.access$000(JEditorPaneBug.java:9)
at JEditorPaneBug$1.run(JEditorPaneBug.java:13)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample application, noting the stack trace on the console.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the frame to open.
ACTUAL -
An ArrayIndexOutOfBoundsException occurred
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException: 0
at javax.swing.text.BoxView.getOffset(BoxView.java:1079)
at javax.swing.text.BoxView.childAllocation(BoxView.java:669)
at javax.swing.text.CompositeView.getChildAllocation(CompositeView.java:215)
at javax.swing.text.BoxView.getChildAllocation(BoxView.java:427)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(BasicTextUI.java:1856)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(BasicTextUI.java:1832)
at java.awt.Container.layout(Container.java:1020)
at java.awt.Container.doLayout(Container.java:1010)
at java.awt.Container.validateTree(Container.java:1092)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validateTree(Container.java:1099)
at java.awt.Container.validate(Container.java:1067)
at java.awt.Window.show(Window.java:461)
at java.awt.Component.show(Component.java:1133)
at java.awt.Component.setVisible(Component.java:1088)
at JEditorPaneBug.demoBug(JEditorPaneBug.java:32)
at JEditorPaneBug.access$000(JEditorPaneBug.java:9)
at JEditorPaneBug$1.run(JEditorPaneBug.java:13)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.EventQueue;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class JEditorPaneBug {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
demoBug();
}
});
}
private static void demoBug() {
try {
// if you comment the following line out and uncomment succeeding line, the bug does not occur
// the HTML comment seems to be necessary to reproduce the issue
String html = "<html><!-- this is a comment --><body><h1>Hello, world</h1></body></html>";
//String html = "<html><body><h1>Hello, world</h1></body></html>";
JEditorPane editorPane = new JEditorPane("text/html", html);
editorPane.setText("<html><body>hello, world</body></html");
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(400, 400);
f.getContentPane().add(new JScrollPane(editorPane));
f.setLocationRelativeTo(null);
f.setVisible(true);
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Remove the comment from the HTML
(Incident Review ID: 260981)
======================================================================