JDK-6945177 : ArrayIndexOutOfBoundsException in JTextField
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2010-04-19
  • Updated: 2011-01-19
  • Resolved: 2010-07-06
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
ver XP

A DESCRIPTION OF THE PROBLEM :
The problem occurs if I switch between TextFields while I type something on the keyboard. I don't know exactly when the error occurs. I have to switch and type for a longer time, then the exception will be thrown.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
typing on the keyboard and switching between TextFields on the same time

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the typed text in the TextField
ACTUAL -
Exception

ERROR MESSAGES/STACK TRACES THAT OCCUR :
--- Message: 7---
java.lang.ArrayIndexOutOfBoundsException: 7

	 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:6311)
	 at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3285)
	 at java.awt.Component.processEvent(Component.java:6032)
	 at java.awt.Container.processEvent(Container.java:2041)
	 at java.awt.Component.dispatchEventImpl(Component.java:4630)
	 at java.awt.Container.dispatchEventImpl(Container.java:2099)
	 at java.awt.Component.dispatchEvent(Component.java:4460)
	 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:4460)
	 at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
PUBLIC COMMENTS I used the following test to reproduce the bug: ------------ package crs.cr6945177; import javax.swing.*; public class Text6945177 { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ex) { ex.printStackTrace(); } JTextField textField1 = new JTextField(30); JTextField textField2 = new JTextField(30); JPanel content = new JPanel(); content.add(textField1); content.add(textField2); JFrame frame = new JFrame(); frame.setContentPane(content); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); } } ------------ Unfortunately I can't reproduce the bug. I analized the stacktrace from the bug and found out that code in the Utilities.getTabbedTextOffset method was fixed in CR 6857057. Try a new jdk build and observe that the error disappeared.
06-07-2010