Name: joT67522 Date: 10/14/97
Running the enclosed code results in an IllegalArgumentException
being thrown from GregorianCalendar.computeTime().
Looks to be a defect in the yy->yyyy adjustment logic:
- assume current century
- parse date (calling cal.getTime())
- if parsed date is outside century window,
add 100 years.
This means that the calendar is being asked to
validate 29-Feb-1900, which is not valid.
Suggest yy expansion be done *before* validation, as
the year affects the valid field values.
import java.text.*;
import java.util.*;
public class LeapTest {
public static void main(String[] args) {
DateFormat fmt = new SimpleDateFormat("M/d/yy");
fmt.getCalendar().setLenient(false);
try {
System.out.println(fmt.parse("2/29/00"));
}
catch(ParseException e) { e.printStackTrace(); }
}
}
======================================================================
- duplicates
-
JDK-4073644 parsing 1/1/00 gives back 1900
-
- Closed
-