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

javax.swing.SpinnerNumberModel.getNext/PreviousValue() has incorrect behavior

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.6



      Name: ooR10001 Date: 12/18/2000


      javax.swing.SpinnerNumberModel.getNextValue() and
      javax.swing.SpinnerNumberModel.getPreviousValue() methods has incorrect behavior when
      stepSize is less then 0. In this case the result returned by getNextValue() may be less
      then upper bound but less then lower bound of the SpinnerNumberModel. This is breaking the
      invariant (minimum <= value <= maximum) because non-null value is returned by
      getNextValue() method. Also, getPreviousValue() method can break the invariant when the
      returned result is greater then lower bound but greater then upper bound.
      These cases cause that the sequential calls of getNextValue() (or getPreviousValue())
      method will never return null and SpinnerModel will be infinite inspite of the presence of
      upper and lower bounds. It contradicts with the concept of SpinnerNumberModel and needs to
      be fixed.


      Following test is demonstrate this bug:
      ----------------------------------------------
      import javax.swing.SpinnerNumberModel;

      public class t {

        public static void main(String[] args) {
            SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 3, -1);
            Number value = (Number)model.getNextValue();
            if (value == null) {
                System.out.println("Test PASSED");
            } else {
                System.out.println("getNextValue() returns " + value.intValue());
                System.out.println("Test FAILED");
            }
        }
      }
      ----------------------
      Test output:
      ----------------------
      getNextValue() returns 0
      Test FAILED
      ----------------------

      ======================================================================

            svioletsunw Scott Violet (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: