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

SpinnerDateModel.setValue(Object) throws exception with incorrect message

XMLWordPrintable

    • b09
    • x86
    • windows_xp

      Name: rmT116609 Date: 09/20/2004


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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      I discovered this bug by accident, when I was creating a date model for a JSpinner but using Calendar object values instead of Date values.

      If you pass a value to a SpinnerDateModel via the setValue(Object) method, and that object is not a Date, it throws an IllegalArgumentException, as per the documentation. However, the message of that exception states that the value is null, when it clearly is not.

      The source code of the method includes a quick check to see whether the value is valid:

      if ((value == null) || !(value instanceof Date)) {
      throw new IllegalArgumentException("null value");
      }

      This could easily be expanded to provide a better exception message:

      if (value == null) {
      throw new IllegalArgumentException ("null value");
      }
      else if (!(value instanceof Date)) {
      throw new IllegalArgumentException ("value is not a java.util.Date");
      }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See code sample.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program should fail because the type of data entered into the spinner model is incorrect.
      ACTUAL -
      The program fails, but indicates that the data entered into the spinner model is null.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.IllegalArgumentException: null value
              at javax.swing.SpinnerDateModel.setValue(SpinnerDateModel.java:433)
              at SpinnerDateModelTest.main(SpinnerDateModelTest.java:7)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.SpinnerDateModel;

      public class SpinnerDateModelTest {

        public static void main (String[] args) {
          SpinnerDateModel model = new SpinnerDateModel ();
          model.setValue (new Integer (42)); // exception says value is null
        }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Make sure you put valid values in your spinner model. The bug really doesn't have any impact, now that I know what is causing the problem, because the workaround is trivial.
      (Incident Review ID: 311271)
      ======================================================================
      ###@###.### 10/4/04 14:14 GMT

            kereminsunw Konstantin Eremin (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: