Invoking pack() on JFrame with JTextField with RTL text from doc listener hangs.

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.7.0_03"
      Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux peregrin 3.0.0-15-generic #26-Ubuntu SMP Fri Jan 20 17:23:00 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When invoking pack() on a JFrame from the insertUpdate() method of a DocumentListener on a JTextField contained in that frame, which is currently displaying selected right-to-left (for instance Hebrew or Arabic) text will cause the pack() method never to return and the thread to hang!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JFrame containing a JTextField. Register a DocumentListener on the field's document, and in the insertUpdate() method invoke pack() on the frame. Enter some right-to-left text, select it, and try to replace it by typing on the keyboard.

      I have included a test case which performs these actions. This will display a window containing a text field with some Hebrew text which is already selected. Typing anything on the keyboard will trigger the bug (the text will not change and the program will hang).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect the text to be replaced with whatever I type and the program to continue running normally.
      ACTUAL -
      The pack() method never returns, the text is not replaced and the program hangs.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import javax.swing.JFrame;
      import javax.swing.JTextField;
      import javax.swing.event.DocumentEvent;
      import javax.swing.event.DocumentListener;

      public class Bug {
          public static void main(String[] args) {
              final JFrame frame = new JFrame("Bug");
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              JTextField field = new JTextField("\u05e2\u05d1\u05e8\u05d9\u05ea");
              frame.getContentPane().add(field, BorderLayout.CENTER);
              field.selectAll();
              field.getDocument().addDocumentListener(new DocumentListener() {
                  public void insertUpdate(DocumentEvent e) {
                      frame.pack(); // Will never return if RTL text is currently selected in the field
                  }
                  public void removeUpdate(DocumentEvent e) {}
                  public void changedUpdate(DocumentEvent e) {}
              });
              frame.pack();
              frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I have not found any workaround yet!

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: