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

(cal) Exception for Gregorian Calendar class created with 3 parameter constructor

    XMLWordPrintable

Details

    • b53
    • 6
    • b92
    • x86
    • linux, windows_xp

    Backports

      Description

        FULL PRODUCT VERSION :
        Standard Edition (build 1.5.0_07-b03)

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

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        not relevant

        A DESCRIPTION OF THE PROBLEM :
        When a constructor specifying class fields is used to create a Gregorian Calendar object and lenient flag is set true, after changing a time related field
        every call to get(..) method to access Gregorian Calendar fields throws
        an exception.

        following code will generate exception
            GregorianCalendar gc = new GregorianCalendar(2006,5,16);
            gc.setLenient(false);
            gc.set(GregorianCalendar.HOUR_OF_DAY, 10);
            gc.get(GregorianCalendar.YEAR);

        the problem is obviousely in computeTime() method of Gregorian Calendar
        and exception is thrown by following check:
        if (!isLenient()) {
        for (int field = 0; field < FIELD_COUNT; field++) {
        if (!isExternallySet(field)) {
        continue;
        }
        if (originalFields[field] != internalGet(field)) {
        // Restore the original field values
        System.arraycopy(originalFields, 0, fields, 0, fields.length);
        throw new IllegalArgumentException(getFieldName(field));
        }
        }
        }

        (problem do not exist in java version 1.4.2_04-b05)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        run following code:
            GregorianCalendar gc = new GregorianCalendar(2006,5,16);
            gc.setLenient(false);
            gc.set(GregorianCalendar.HOUR_OF_DAY, 10);
            gc.get(GregorianCalendar.YEAR); <-Illegal Argument exception


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        get the value of year field of GregorianCalendar
        ACTUAL -
        Illegal Argument exception

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "main" java.lang.IllegalArgumentException: HOUR

        at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:2481)

        at java.util.Calendar.updateTime(Calendar.java:2260)

        at java.util.Calendar.complete(Calendar.java:1305)

        at java.util.Calendar.get(Calendar.java:1088)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
            GregorianCalendar gc = new GregorianCalendar(2006,5,16);
            gc.setLenient(false);
            gc.set(GregorianCalendar.HOUR_OF_DAY, 10);
            gc.get(GregorianCalendar.YEAR); <-Illegal Argument exception

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        use a no parameter constructor and field set methods

        Release Regression From : 1.4.2_11
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

        Attachments

          Issue Links

            Activity

              People

                okutsu Masayoshi Okutsu
                ndcosta Nelson Dcosta (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: