JDK-7141488 : JTextPane throws ArrayIndexOutOfBoundsException with Unicode and System L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-01-31
  • Updated: 2022-02-17
  • Resolved: 2022-02-17
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
tbdResolved
Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
Nothing special for the configuration, problem reproduced on several computers (different OS, different Java version, ...)

A DESCRIPTION OF THE PROBLEM :
The JTextPane.setText() method throws an ArrayIndexOutOfBoundsException if all the following conditions are met :
- Using the System L&F, with a call to UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
- Using a text having some unicode characters that are not used very often (example provided is with some characters from Bangla language)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided example to display a Window with a JTextPane and 2 buttons, one with a text in Bangla language, the other one with a simple "A".
Clicking on either button should copy the text of the button in the JTextPane.
It works with the "A" button, but the same code with the button in Bangla language throws an ArrayIndexOutOfBoundsException.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When clicking on the button with the text in Bangla language, the JTextPane content should be replaced by the text in Bangla.
ACTUAL -
Instead of the expected result, an ArrayIndexOutOfBoundsException is thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 218
        at sun.font.ExtendedTextSourceLabel.getLineBreakIndex(ExtendedTextSourceLabel.java:459)
        at java.awt.font.TextMeasurer.calcLineBreak(TextMeasurer.java:325)
        at java.awt.font.TextMeasurer.getLineBreakIndex(TextMeasurer.java:561)
        at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:358)
        at java.awt.font.LineBreakMeasurer.nextLayout(LineBreakMeasurer.java:440)
        at javax.swing.text.TextLayoutStrategy.sync(TextLayoutStrategy.java:323)
        at javax.swing.text.TextLayoutStrategy.insertUpdate(TextLayoutStrategy.java:70)
        at javax.swing.text.FlowView.loadChildren(FlowView.java:143)
        at javax.swing.text.CompositeView.setParent(CompositeView.java:139)
        at javax.swing.text.FlowView.setParent(FlowView.java:289)
        at javax.swing.text.CompositeView.replace(CompositeView.java:217)
        at javax.swing.text.BoxView.replace(BoxView.java:181)
        at javax.swing.text.CompositeView.loadChildren(CompositeView.java:114)
        at javax.swing.text.CompositeView.setParent(CompositeView.java:139)
        at javax.swing.plaf.basic.BasicTextUI$RootView.setView(BasicTextUI.java:1330)
        at javax.swing.plaf.basic.BasicTextUI.setView(BasicTextUI.java:695)
        at javax.swing.plaf.basic.BasicTextUI.modelChanged(BasicTextUI.java:684)
        at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1856)
        at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:202)
        at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:749)
        at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:708)
        at javax.swing.text.DefaultEditorKit.read(DefaultEditorKit.java:271)
        at javax.swing.JEditorPane.setText(JEditorPane.java:1415)
        at TestJTextPane.actionPerformed(TestJTextPane.java:68)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
        at java.awt.Component.processMouseEvent(Component.java:6505)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6270)
        at java.awt.Container.processEvent(Container.java:2229)
        at java.awt.Component.dispatchEventImpl(Component.java:4861)
        at java.awt.Container.dispatchEventImpl(Container.java:2287)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
        at java.awt.Container.dispatchEventImpl(Container.java:2273)
        at java.awt.Window.dispatchEventImpl(Window.java:2713)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
        at java.awt.EventQueue.access$000(EventQueue.java:101)
        at java.awt.EventQueue$3.run(EventQueue.java:666)
        at java.awt.EventQueue$3.run(EventQueue.java:664)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
        at java.awt.EventQueue$4.run(EventQueue.java:680)
        at java.awt.EventQueue$4.run(EventQueue.java:678)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class TestJTextPane extends JFrame implements ActionListener {

  private JTextPane textPane;

  public TestJTextPane() {
    super();
    build();
  }

  private void build() {
    setTitle("Test JTextPane");
    setSize(320, 240);
    setLocationRelativeTo(null);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setContentPane(buildContentPane());
  }

  private JPanel buildContentPane() {
    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());

    textPane = new JTextPane();
    textPane.setPreferredSize(new Dimension(300, 100));
    panel.add(textPane);

    JButton button1 = new JButton(
      "[[bn:\u09a8\u09cb\u09a4\u09cd\u09b0\u09cd\u200c \u09a6\u09be\u09ae \u09a6\u09cd\u09af \u09aa\u09be\u09b0\u09bf]]\n");
    button1.addActionListener(this);
    panel.add(button1);

    JButton button2 = new JButton("A");
    button2.addActionListener(this);
    panel.add(button2);

    return panel;
  }

  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source instanceof JButton) {
      JButton button = (JButton) source;
      textPane.setText(textPane.getText() + button.getText());
    }
  }

  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
      // Not important
    } catch (InstantiationException e) {
      // Not important
    } catch (IllegalAccessException e) {
      // Not important
    } catch (UnsupportedLookAndFeelException e) {
      // Not important
    }

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        TestJTextPane window = new TestJTextPane();
        window.setVisible(true);
      }
    });
  }
}

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

Comments
With even bangla font installed, not reproducible in windows10
17-02-2022

Not reproducible on Windows 10 with JDK 10
19-09-2017

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014