United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6828938 : REGRESSION:IndexOutOfBounds exception throws in BasicTextUI

Details
Type:
Bug
Submit Date:
2009-04-10
Status:
Closed
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2009-07-16
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Duplicate
Affected Versions:
6u14
Fixed Versions:

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
Regression issue reported from 6uN EA forum:

To reproduce:
-Run the program below
-start typing text in the text field
-while typing, keep drag-selecting text from the right to the left (selected text gets replaced by what you type)
-you should get the exception below.

Cannot reproduce this on 6u12.

[code]

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class TestDragCaret {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame("Test drag caret");
                frame.getContentPane().add(new JTextField(40));
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }
}
[/code]

Info:
-Windows XP sp3
java version "1.6.0_14-ea"
Java(TM) SE Runtime Environment (build 1.6.0_14-ea-b04)
Java HotSpot(TM) Client VM (build 14.0-b13, mixed mode, sharing)

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 8
	at sun.font.FontDesignMetrics.charsWidth(FontDesignMetrics.java:492)
	at javax.swing.text.Utilities.getTabbedTextOffset(Utilities.java:381)
	at javax.swing.text.Utilities.getTabbedTextOffset(Utilities.java:302)
	at javax.swing.text.Utilities.getTabbedTextOffset(Utilities.java:286)
	at javax.swing.text.PlainView.viewToModel(PlainView.java:403)
	at javax.swing.text.FieldView.viewToModel(FieldView.java:263)
	at javax.swing.plaf.basic.BasicTextUI$RootView.viewToModel(BasicTextUI.java:1540)
	at javax.swing.plaf.basic.BasicTextUI.viewToModel(BasicTextUI.java:1089)
	at javax.swing.text.DefaultCaret.moveCaret(DefaultCaret.java:311)
	at javax.swing.text.DefaultCaret.mouseDragged(DefaultCaret.java:565)
	at java.awt.AWTEventMulticaster.mouseDragged(AWTEventMulticaster.java:303)
	at java.awt.Component.processMouseMotionEvent(Component.java:6285)
	at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3285)
	at java.awt.Component.processEvent(Component.java:6006)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4604)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4434)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4255)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Window.dispatchEventImpl(Window.java:2475)
	at java.awt.Component.dispatchEvent(Component.java:4434)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

                                    

Comments
EVALUATION

Clarification: "Closed as Duplicate" here means that this bug is already fixed indirectly in the course of another bugfix (6857057), and the fix will appear in some near JDK update release.
                                     
2009-08-05
EVALUATION

Sometimes an offset calculated by Utilities.getTabbedTextOffset() points to the position beyond the passed-in segment area. This is a bug. Usually there's no harm as the segment usually contains data past the end of the area, but in rare cases when it does not, charsWidth() throws an exception.

This bug is revealed by 6760148 where getTabbedTextOffset() tries to actually read segment data at the calculated offset.

I think the best solution here is to rollback changes introduced by 6760148 and check for width overflow in GlyphView.breakView(), ie, the actual place where it matters.

It happened that Utilities.getTabbedTextOffset() is too low-level and too general for this particular task.
                                     
2009-06-05



Hardware and Software, Engineered to Work Together