FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
A DESCRIPTION OF THE PROBLEM :
currently DateFormat does not throw a NullPointerException when the parameter to setCalendar or setNumberFormat is null. This causes subsequent calls to the format method to fail
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Consider the following class:
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Bug {
public static void main(String[] args) throws ParseException {
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
fmt.setCalendar(null);
fmt.setNumberFormat(null);
fmt.format(new Date());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect DateFormat to prevent callers from moving it into an illegal state. Both
fmt.setCalendar(null);
and
fmt.setNumberFormat(null);
must throw a NullPointerException in the code above
ACTUAL -
A NullPointerException is thrown at the line
fmt.format(new Date());
because its required internal variables were set to null
REPRODUCIBILITY :
This bug can be reproduced always.
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
A DESCRIPTION OF THE PROBLEM :
currently DateFormat does not throw a NullPointerException when the parameter to setCalendar or setNumberFormat is null. This causes subsequent calls to the format method to fail
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Consider the following class:
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Bug {
public static void main(String[] args) throws ParseException {
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
fmt.setCalendar(null);
fmt.setNumberFormat(null);
fmt.format(new Date());
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect DateFormat to prevent callers from moving it into an illegal state. Both
fmt.setCalendar(null);
and
fmt.setNumberFormat(null);
must throw a NullPointerException in the code above
ACTUAL -
A NullPointerException is thrown at the line
fmt.format(new Date());
because its required internal variables were set to null
REPRODUCIBILITY :
This bug can be reproduced always.
- duplicates
-
JDK-8169480 Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
- Closed
- relates to
-
JDK-4651757 API: Calendar.setTime() throws NullPointerException with a null TimeZone
- Closed