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

JSpinner does not remove listener connections in setModel()

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_06"
      Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
      Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux porro 2.6.24-19-generic #1 SMP Fri Jul 11 23:41:49 UTC 2008 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      JSpinner does not remove listener connections to existing models when a new model is set using setModel(). The code in question:

          public void setModel(SpinnerModel model) {
              if (model == null) {
                  throw new IllegalArgumentException("null model");
              }
              if (!model.equals(this.model)) {
                  SpinnerModel oldModel = this.model;
                  this.model = model;
                  if (modelListener != null) {
                      this.model.addChangeListener(modelListener);
                  }
                  firePropertyChange("model", oldModel, model);
                  if (!editorExplicitlySet) {
                      setEditor(createEditor(model)); // sets editorExplicitlySet true
                      editorExplicitlySet = false;
                  }
                  repaint();
                  revalidate();
              }
          }

      Clearly lacks the necessary oldModel.removeChangeListener(modelListener).

      I have recently found very similar bugs in three different swing components, so I would suggest checking through other components as well for similar bugs, as these "dropped" listener connections can cause quite some memory leakage and slowdown.


      REPRODUCIBILITY :
      This bug can be reproduced always.

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: