-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
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
-------------------------------------------------
======================================================================