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

JComboBox.removeAllItems() triggers ActionListeners

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.2
    • client-libs



      Name: rmT116609 Date: 03/10/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)


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

      A DESCRIPTION OF THE PROBLEM :
      The method JComboBox.removeAllItems() now triggers ActionListeners for the JComboBox. In previous versions, this wasn't the case. I could not find any documentation stating that this change was intended, so I'm not sure if it's a bug or intentional. Code that worked under 1.4.1 and versions previous might be broken under 1.4.2 if an actionPerformed() dereferences getSelectedItem() without a null check.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run RemoveAllTest under 1.4.1 & 1.4.2. The actionPerformed() method is invoked under 1.4.2 but not 1.4.1.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Not sure, I guess I don't understand why removing the items constitutes an 'action'.
      ACTUAL -
      Calling removeAllItems() fires an action event.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.event.*;

      public class RemoveAllTest {

        public static void main(String[] args) {
          final JComboBox combo = new JComboBox();
          combo.addItem("one");
          combo.addItem("two");
          combo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              System.out.println(
                "combo actionPerformed()...getSelectedItem(): "
                +combo.getSelectedItem());
            }
          });
          combo.removeAllItems();
        }
      }
      ---------- END SOURCE ----------
      (Incident Review ID: 241501)
      ======================================================================

            kizune Alexander Zuev
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: