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

Redundant source code in JComboBox

XMLWordPrintable

      FULL PRODUCT VERSION :
      JRE 1.6.0

      ADDITIONAL OS VERSION INFORMATION :
      WIN XP SP2

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Not relevant

      A DESCRIPTION OF THE PROBLEM :
      In the source code of 1.6.0 I see the method setSelectedItem of javax.swing.JComboBox:
       public void setSelectedItem(Object anObject) {
      Object oldSelection = selectedItemReminder;
              Object objectToSelect = anObject;
      if (oldSelection == null || !oldSelection.equals(anObject)) {

      if (anObject != null && !isEditable()) {
      // For non editable combo boxes, an invalid selection
      // will be rejected.
      boolean found = false;
      for (int i = 0; i < dataModel.getSize(); i++) {
                          Object element = dataModel.getElementAt(i);
      if (anObject.equals(element)) {
      found = true;
                              objectToSelect = element;
      break;
      }
      }
      if (!found) {
      return;
      }
      }

      // Must toggle the state of this flag since this method
      // call may result in ListDataEvents being fired.
      selectingItem = true;
      dataModel.setSelectedItem(objectToSelect);
      selectingItem = false;

      if (selectedItemReminder != dataModel.getSelectedItem()) {
      // in case a users implementation of ComboBoxModel
      // doesn't fire a ListDataEvent when the selection
      // changes.
      selectedItemChanged();
      }
      }
      fireActionEvent();
          }

      The use of objectToSelect is not usefull. It could be removed (like in the 1.4.2 version)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See the source code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Set selectedItem execute in less than 1 second
      ACTUAL -
      Set selectedItem execute in really more than 1 second if you are executing out of the same net where the server (hosting the japplet) is.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Really slow execution

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Try to create an applet in which select an item with setSelectedIndex method.
      It is slow with 1.5 and 1.6, but it's quick with 1.4.2

      Even adding an item by code (addItem) do the same.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I think the slowing of the operations could be caused by this and by other things linked to this code "added".
      But why add a code for slowing? Is it a Microsoft dictate?

      The only workaround available is to use JDK 1.4.2 (more quick than 1.6 anc 1.5)

            alexp Alexander Potochkin (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: