setText() freezes JVM if gets called from insertUpdate within DocumentListener

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P2
    • None
    • Affects Version/s: 1.1.6
    • Component/s: client-libs
    • None
    • generic
    • solaris_2.5.1

      When
      I call on setText() method in insertUpdate() to set the value of
      textfield , it causes the whole JVM to freeze.
      No other interaction with the tiny test case is possible.
      There is no problem with calling the setText() method outside
      of any methods of DocumentListener. To reproduce the problem just enter 123 in the textfield area.

      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.event.*;
      import com.sun.java.swing.*;
      import com.sun.java.swing.border.*;
      import com.sun.java.swing.plaf.*;
      import com.sun.java.swing.text.*;
      import java.beans.*;
      import java.util.*;
      import java.text.*;
      import com.sun.java.swing.plaf.basic.*;

      public class TestTextField extends Object
      {
         JTextField text = new JTextField();
         DateTextDocumentListener listener = new DateTextDocumentListener();
         Document doc = null;
         

         public TestTextField()
         {
            doc = text.getDocument();
            doc.addDocumentListener(listener);
            
            JFrame frame = new JFrame("TestTextField");
            Container cont = frame.getContentPane();
            cont.setLayout(new BorderLayout());
            cont.add("North", text);
            
            frame.setSize(500, 500);
            frame.setVisible(true);
         }
         
            

         public static void main(String[] args)
         {
         
            new TestTextField();
         }





         private class DateTextDocumentListener implements DocumentListener
         {
            
            public void insertUpdate(DocumentEvent e)
            {
               
               int value = Integer.parseInt(text.getText().trim());
               if(value < 1 || value > 31)
               {
                  System.out.println("value is greater than 31 or less than 1");
                  System.out.println("Value is " + value);
                  System.out.println("Setting value to 1");
                  doc.removeDocumentListener(listener);
                  text.setText("1");
                  doc.addDocumentListener(listener);
               }

            }//endofinsertUpdatemethod
            
            public void removeUpdate(DocumentEvent e)
            {

       
            }//endofremoveUpdatemethod
            
            public void changedUpdate(DocumentEvent e)
            {
            }
            
         }//endofDateTextDocumentListenerclass
         
         
      }
      nasser.nouri@Corp 1998-07-20

            Assignee:
            Tim Prinzing (Inactive)
            Reporter:
            Nasser Nouri (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: