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

setState() now causes stack overflow problems

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: client-libs

      Description



      Name: yyT116575 Date: 10/24/2000


      C:\jdk1.2.2>java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      I think that the code example tells the story here. It looks like a fix to
      setState() which apparently wasnt registering with the change listener in the
      past is now causing a recursive call situation.

      /*
         Typical code to set the other menu checkbox to false if one is selected.
         You will notice that a Stack Overflow occurs when the setState() method
         of either button is called. I know that JRadioButtonMenuItem could be used
         however sometimes you want to explicitly control which menu items are
      checked.
      */


      import java.awt.event.*;
      import javax.swing.*;


      class Test extends JFrame {

         JMenuBar mb = new JMenuBar();
         JMenu menu = new JMenu("File");
         JCheckBoxMenuItem menuItem1 = new JCheckBoxMenuItem("Test Item 1", false);
         JCheckBoxMenuItem menuItem2 = new JCheckBoxMenuItem("Test Item 2", false);

         Test() {
            setBounds(100,100,100,100);
            setJMenuBar(mb);
            mb.add(menu);
            menu.add(menuItem1);
            menu.add(menuItem2);
            menuItem1.addItemListener(new menuItemHandler1(this));
            menuItem2.addItemListener(new menuItemHandler2(this));
            setVisible(true);
         }

         public static void main(String argv[]) {
            new Test();
         }

      }

      class menuItemHandler1 implements ItemListener
      {

         Test t;

         menuItemHandler1(Test t) {
            this.t = t;
         }

         public void itemStateChanged( ItemEvent e )
         {
            t.menuItem2.setState(false);
         }

      }

      class menuItemHandler2 implements ItemListener
      {

         Test t;

         menuItemHandler2(Test t) {
            this.t = t;
         }

         public void itemStateChanged( ItemEvent e )
         {
            t.menuItem1.setState(false);
         }

      }
      (Review ID: 110708)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                peterz Peter Zhelezniakov (Inactive)
                Reporter:
                yyoungsunw Yung-ching Young (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: