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

java.util.GregorianCalendar.setGregorianChange(Date) fails with Long.MIN_VALUE

XMLWordPrintable

      Name: dfC67450 Date: 06/03/98



      java.util.GregorianCalendar.setGregorianChange(Date cutover) sets the same year and era
      when cutover is Date(Long.MIN_VALUE) and Date(Long.MAX_VALUE)

      Javadoc says about setGregorianCalendar

          To obtain a pure Julian calendar, set the change date to
          Date(Long.MAX_VALUE). To obtain a pure Gregorian calendar,
          set the change date to Date(Long.MIN_VALUE).

      Here is the test demonstrating the bug:

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

      public class Test {
          public static void main (String args[]){
            GregorianCalendar calendar = new GregorianCalendar();

            calendar.setGregorianChange(new Date(Long.MIN_VALUE));
            Date date1 = calendar.getGregorianChange();

            calendar.setGregorianChange(new Date(Long.MAX_VALUE));
            Date date2 = calendar.getGregorianChange();

            calendar.setTime(date1);
            int year1 = calendar.get(Calendar.YEAR);
            int era1 = calendar.get(Calendar.ERA);

            calendar.setTime(date2);
            int year2 = calendar.get(Calendar.YEAR);
            int era2 = calendar.get(Calendar.ERA);

            if (year1 == year2 && era1 == era2) {
              System.out.println("test failed");
              System.out.println("cutover date is Date(Long.MIN_VALUE)");
              System.out.println(" cutover year: " + year1);
              System.out.println(" cutover era: " + era1);
              System.out.println("");
              System.out.println("cutover date is Date(Long.MAX_VALUE)");
              System.out.println(" cutover year: " + year2);
              System.out.println(" cutover era: " + era2);
            } else {
              System.out.println("test passed");
            }
          }
      }
      ---------Output from the test---------------------
      test failed
      cutover date is Date(Long.MIN_VALUE)
        cutover year: 292269055
        cutover era: 0
       
      cutover date is Date(Long.MAX_VALUE)
        cutover year: 292269055
        cutover era: 0
      -------------------------------------------------

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

            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: