Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5080391

ArrayIndexOutOfBounds when "undo" of Left-to-Right text insert.

    Details

      Description

      Name: jl125535 Date: 07/29/2004


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

      java version "1.4.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_04-b04)
      Java HotSpot(TM) Client VM (build 1.4.0_04-b04, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]


      A DESCRIPTION OF THE PROBLEM :
      The javax.swing.text.AbstractDocument$BranchElement.replace(...) method throws an ArrayIndexOutOfBoundsException when using an UndoManager on the default document of a JTextArea and you try to undo the insertion of a LEFT-TO-RIGHT language (e.g. Arabic) that is immediately followed by setting the component orientation on the JTextArea.

      The exception only occurs with the first left-to-right character inserted. Inserting more than a single character does not correct the first character but the 2nd-Nth character can be undone.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the included executable test case.
      Press the "Insert Text" button followed by the "Undo" button.

      An exception will be printed to the screen and the text inserted will not be removed from the text area.,


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The text insert should be removed and no exception should be printed.
      ACTUAL -
      Exception below is printed to the screen and the text is not removed from the text area.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException
      at java.lang.System.arraycopy(Native Method)
      at javax.swing.text.AbstractDocument$BranchElement.replace(AbstractDocument.java:2294)
      at javax.swing.text.AbstractDocument$ElementEdit.undo(AbstractDocument.java:3083)
      at javax.swing.undo.CompoundEdit.undo(CompoundEdit.java:46)
      at javax.swing.text.AbstractDocument$DefaultDocumentEvent.undo(AbstractDocument.java:2804)
      at javax.swing.undo.UndoManager.undoTo(UndoManager.java:210)
      at javax.swing.undo.UndoManager.undo(UndoManager.java:275)
      at UndoRedoError$2.actionPerformed(UndoRedoError.java:52)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2167)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
      at java.awt.Component.processMouseEvent(Component.java:5465)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3089)
      at java.awt.Component.processEvent(Component.java:5230)
      at java.awt.Container.processEvent(Container.java:1961)
      at java.awt.Component.dispatchEventImpl(Component.java:3933)
      at java.awt.Container.dispatchEventImpl(Container.java:2019)
      at java.awt.Component.dispatchEvent(Component.java:3781)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4205)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3885)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3815)
      at java.awt.Container.dispatchEventImpl(Container.java:2005)
      at java.awt.Window.dispatchEventImpl(Window.java:1764)
      at java.awt.Component.dispatchEvent(Component.java:3781)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.ComponentOrientation;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JScrollPane;
      import javax.swing.JTextArea;
      import javax.swing.undo.UndoManager;


      public class UndoRedoError
      {
          private JTextArea textArea_ = new JTextArea();

          private UndoManager manager_ = new UndoManager();


          public static void main(String[] args)
          {
              UndoRedoError demo = new UndoRedoError();
              demo.init();
          }

          public void init()
          {
              JFrame frame = new JFrame("Undo - Redo Error");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              JScrollPane scrollPane = new JScrollPane(textArea_);

              JButton insertArabic = new JButton("Insert Text");
              insertArabic.addActionListener(new ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      textArea_.insert("\u0633", textArea_.getText().length());
                      textArea_.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
                  }
              });

              textArea_.getDocument().addUndoableEditListener(manager_);

              JButton undo = new JButton("Undo");
              undo.addActionListener(new ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      if (manager_.canUndo())
                      {
                          manager_.undo();
                      }
                  }
              });

              frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(insertArabic, BorderLayout.NORTH);
              frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
              frame.getContentPane().add(undo, BorderLayout.SOUTH);
              frame.setSize(400, 600);
              frame.show();
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None found.
      (Incident Review ID: 290039)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jleesunw Jon Lee (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: