DateFormat getDateInstance, getDateTimeInstance, getTimeInstance methods
do not always throw IllegalArgumentException when the style is invalid.
The methods should throw IllegalArgumentException when the style value is not
a valid value (style != SHORT, MEDIUM, LONG, FULL, DEFAULT).
Some examples:
--------
DateFormat df = DateFormat.getDateTimeInstance(4, 2);
System.out.println("Date: " + df.format(someDate));
Date: {1} {0} 11:36:41 AM
--------
DateFormat df = DateFormat.getDateTimeInstance(2, -1);
System.out.println("Date: " + df.format(someDate));
Date: 19-Feb-99
--------
DateFormat df = DateFormat.getDateTimeInstance(2, 123);
java.lang.ArrayIndexOutOfBoundsException: 123
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java)
at java.text.DateFormat.get(DateFormat.java)
at java.text.DateFormat.getDateTimeInstance(DateFormat.java)
at getDateTimeInstanceTests.Test04(getDateTimeInstanceTests.java:220)
at getDateTimeInstanceTests.main(getDateTimeInstanceTests.java:63)
--------
DateFormat df = DateFormat.getDateTimeInstance(-12, -12);
java.lang.IllegalArgumentException: No date or time style specified
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java)
at java.text.DateFormat.get(DateFormat.java)
at java.text.DateFormat.getDateTimeInstance(DateFormat.java)
at getDateTimeInstanceTests.Test03(getDateTimeInstanceTests.java:186)
at getDateTimeInstanceTests.main(getDateTimeInstanceTests.java:60)
do not always throw IllegalArgumentException when the style is invalid.
The methods should throw IllegalArgumentException when the style value is not
a valid value (style != SHORT, MEDIUM, LONG, FULL, DEFAULT).
Some examples:
--------
DateFormat df = DateFormat.getDateTimeInstance(4, 2);
System.out.println("Date: " + df.format(someDate));
Date: {1} {0} 11:36:41 AM
--------
DateFormat df = DateFormat.getDateTimeInstance(2, -1);
System.out.println("Date: " + df.format(someDate));
Date: 19-Feb-99
--------
DateFormat df = DateFormat.getDateTimeInstance(2, 123);
java.lang.ArrayIndexOutOfBoundsException: 123
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java)
at java.text.DateFormat.get(DateFormat.java)
at java.text.DateFormat.getDateTimeInstance(DateFormat.java)
at getDateTimeInstanceTests.Test04(getDateTimeInstanceTests.java:220)
at getDateTimeInstanceTests.main(getDateTimeInstanceTests.java:63)
--------
DateFormat df = DateFormat.getDateTimeInstance(-12, -12);
java.lang.IllegalArgumentException: No date or time style specified
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java)
at java.text.DateFormat.get(DateFormat.java)
at java.text.DateFormat.getDateTimeInstance(DateFormat.java)
at getDateTimeInstanceTests.Test03(getDateTimeInstanceTests.java:186)
at getDateTimeInstanceTests.main(getDateTimeInstanceTests.java:60)
- relates to
-
JDK-8319628 DateFormat does not mention IllegalArgumentException for invalid style args
- Resolved