JDK-4765331 : JEditorPane editing: Ctrl-A + Delete on wrapped HTML throws BadLocationException
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_7,windows_98
  • CPU: x86,sparc
  • Submitted: 2002-10-18
  • Updated: 2004-12-07
  • Resolved: 2002-11-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description

Name: sv35042			Date: 10/18/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


FULL OPERATING SYSTEM VERSION :
Windows Millennium [Version 4.90.3000]

ADDITIONAL OPERATING SYSTEMS :

A DESCRIPTION OF THE PROBLEM :
When editing the content of a JEditorPane with content type
set to "text/html", a BadLocationException can be thrown
when attempting to delete all text.  Seems to occur only if
the text to be deleted has been wrapped and has been
selected with Ctrl-A.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
(See source code below.)

Set the content type to "text/html" in a JEditorPane, then
setText() to a string that gets wrapped when displayed.

If you then perform the following sequence to delete the
text in the JEditorPane:

1. Click on the JEditorPane
2. Press Ctrl-A to select all
3. Press Delete

a BadLocationException is thrown.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
javax.swing.text.StateInvariantError: GlyphView: Stale view:
javax.swing.text.BadLocationException: Invalid location
        at javax.swing.text.GlyphView.getText(GlyphView.java:102)
        at javax.swing.text.GlyphPainter1.paint(GlyphPainter1.java:95)
        at javax.swing.text.GlyphView.paintTextUsingColor(GlyphView.java:395)
        at javax.swing.text.GlyphView.paint(GlyphView.java:386)
        at javax.swing.text.BoxView.paintChild(BoxView.java:144)
        at javax.swing.text.BoxView.paint(BoxView.java:407)
        at javax.swing.text.BoxView.paintChild(BoxView.java:144)
        at javax.swing.text.BoxView.paint(BoxView.java:407)
        at javax.swing.text.ParagraphView.paint(ParagraphView.java:568)
        at javax.swing.text.html.ParagraphView.paint(ParagraphView.java:220)
        at javax.swing.text.BoxView.paintChild(BoxView.java:144)
        at javax.swing.text.BoxView.paint(BoxView.java:407)
        at javax.swing.text.html.BlockView.paint(BlockView.java:264)
        at javax.swing.text.BoxView.paintChild(BoxView.java:144)
        at javax.swing.text.BoxView.paint(BoxView.java:407)
        at javax.swing.text.html.BlockView.paint(BlockView.java:264)
        at javax.swing.plaf.basic.BasicTextUI$RootView.paint
(BasicTextUI.java:1248)
        at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:565)
        at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:699)
        at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:678)
        at javax.swing.JComponent.paintComponent(JComponent.java:537)
        at javax.swing.JComponent.paint(JComponent.java:804)
        at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4735)
        at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4688)
        at javax.swing.JComponent._paintImmediately(JComponent.java:4632)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4464)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:404)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run
(SystemEventQueueUtilities.java:117)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:443)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy
(EventDispatchThread.java:190)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)

...

(repeats until window is closed)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JEditorPaneBug extends JFrame {
    private JEditorPane editorPane;
    private String unwrappedText =
        "<html><head></head><body>Unwrapped.</body></html>";
    private String wrappedText   =
        "<html><head></head><body><p>This text gets wrapped.</p></body></html>";
    
    public JEditorPaneBug() {
        setSize(320, 240);
        editorPane = new JEditorPane("text/html", unwrappedText);
        editorPane.setPreferredSize(new Dimension(100, 100));
        JButton button = new JButton("setText()");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                editorPane.setText(wrappedText);
                System.out.println("Now click on the JEditorPane,");
                System.out.println("hit Ctrl-A to select all,");
                System.out.println("then Delete to delete the selection.");
                System.out.println("The following exception should be thrown:");
                System.out.println("javax.swing.text.StateInvariantError:
GlyphView: Stale view: javax.swing.text.BadLocationException: Invalid
location");
                System.out.println("\tat javax.swing.text.GlyphView.getText
(GlyphView.java:102)");
                System.out.println("(It seems the text must be long enough to
wrap for the bug to appear.)");
            }
        });
        Container cp = getContentPane();
        cp.setLayout(new FlowLayout());
        cp.add(editorPane);
        cp.add(button);
    }
    
    public static void main(String args[]) {
        JFrame f = new JEditorPaneBug();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLocationRelativeTo(null);
        f.show();
        System.out.println("Click the 'setText()' button.");
    }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Use the mouse to select all text instead of Ctrl-A.
(Review ID: 159709) 
======================================================================

Comments
EVALUATION Name: dsR10138 Date: 10/26/2002 The bug exists because the very first paragraph's layout isn't marked invalid though the corresponding element has changed. The idea of a fix is to relayout paragraph on insert/change/remove update. ###@###.### 2002-10-25 ====================================================================== this bug was refixed in mantis as part of the fix for 4822422 layout(fv) was changed to fv.layoutChanged(View.X_AXIS); fv.layoutChanged(View.Y_AXIS) ###@###.### 2004-12-07 01:36:36 GMT
07-12-2004

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b06
14-06-2004