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

java.util.GregorianCalendar.computeFields() incorrectly computes year

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: dfC67450 Date: 06/04/98



      java.util.GregorianCalendar.computeFields() sets the year to value greater than
      max value in case of large time.

      Javadoc says about getMaximum:
          
         Gets the maximum value for the given time field.

      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      import java.util.*;

      public class Test {
        public static void main (String args[]){
          GregorianCalendarTest calendar = new GregorianCalendarTest();
          calendar.setTime(new Date(Long.MAX_VALUE));
          calendar.computeFields();
          int year = calendar.get(Calendar.YEAR);
          int maxYear = calendar.getMaximum(Calendar.YEAR);
          if (year <= maxYear) {
            System.out.println("Test passed");
          } else {
            System.out.println("Test failed");
            System.out.println(" year: " + year);
            System.out.println(" maxYear: " + maxYear);

          }

        }

      }

      class GregorianCalendarTest extends GregorianCalendar {
               // access to protected method

          public void computeFields() {
             super.computeFields();
          }

      }
      ---------Output from the test---------------------
      Test failed
        year: 292269055
        maxYear: 5000000
      -------------------------------------------------

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

            aliusunw Alan Liu (Inactive)
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: