-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b03
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8343899 | 11.0.26 | Amos SHI | P4 | Resolved | Fixed | b02 |
JDK-8334288 | 11.0.25-oracle | Hari Rakesh | P4 | Resolved | Fixed | b01 |
JDK-8340725 | 8u441 | Johny Jose | P4 | Resolved | Fixed | b01 |
It's well known that Date constructors use 1900-based years, which is very error prone. Here are some apparently inadvertent uses of such constructors in jdk tests, that ought to be fixed. The standard idiom is
new Date(YYYY - 1900, ...)
making it clearer what is going on.
diff --git a/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java b/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java
--- a/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java
+++ b/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java
@@ -1067,7 +1067,7 @@
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
SimpleDateFormat fmt = new SimpleDateFormat("yy/MM/dd hh:ss zzz", Locale.JAPAN);
@SuppressWarnings("deprecation")
- String result = fmt.format(new Date(1999, 0, 1));
+ String result = fmt.format(new Date(1999 - 1900, 0, 1));
logln("format()=>" + result);
if (!result.endsWith("PST")) {
errln("FAIL: SimpleDataFormat.format() did not retrun PST");
diff --git a/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java b/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java
--- a/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java
+++ b/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java
@@ -180,7 +180,7 @@
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
- Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
+ Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
@@ -192,7 +192,7 @@
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
- Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
+ Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
diff --git a/test/jdk/java/util/Calendar/FieldStateTest.java b/test/jdk/java/util/Calendar/FieldStateTest.java
--- a/test/jdk/java/util/Calendar/FieldStateTest.java
+++ b/test/jdk/java/util/Calendar/FieldStateTest.java
@@ -147,7 +147,7 @@
+ "Then, getTime and set week of year to 43.");
@SuppressWarnings("deprecation")
- Date d = new Date(2003 - 1990, OCTOBER, 31);
+ Date d = new Date(2003 - 1900, OCTOBER, 31);
cal.setTime(d);
cal.set(DAY_OF_WEEK, SUNDAY);
cal.set(2003, OCTOBER, 31); // 2003/10/31 is Friday.
new Date(YYYY - 1900, ...)
making it clearer what is going on.
diff --git a/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java b/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java
--- a/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java
+++ b/test/jdk/java/text/Format/DateFormat/DateFormatRegression.java
@@ -1067,7 +1067,7 @@
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
SimpleDateFormat fmt = new SimpleDateFormat("yy/MM/dd hh:ss zzz", Locale.JAPAN);
@SuppressWarnings("deprecation")
- String result = fmt.format(new Date(1999, 0, 1));
+ String result = fmt.format(new Date(1999 - 1900, 0, 1));
logln("format()=>" + result);
if (!result.endsWith("PST")) {
errln("FAIL: SimpleDataFormat.format() did not retrun PST");
diff --git a/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java b/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java
--- a/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java
+++ b/test/jdk/java/time/tck/java/time/format/TCKLocalizedPrinterParser.java
@@ -180,7 +180,7 @@
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
- Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
+ Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
@@ -192,7 +192,7 @@
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
- Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
+ Date oldDate = new Date(1970 - 1900, 0, 0, time.getHour(), time.getMinute(), time.getSecond());
String text = old.format(oldDate);
DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale);
diff --git a/test/jdk/java/util/Calendar/FieldStateTest.java b/test/jdk/java/util/Calendar/FieldStateTest.java
--- a/test/jdk/java/util/Calendar/FieldStateTest.java
+++ b/test/jdk/java/util/Calendar/FieldStateTest.java
@@ -147,7 +147,7 @@
+ "Then, getTime and set week of year to 43.");
@SuppressWarnings("deprecation")
- Date d = new Date(2003 - 1990, OCTOBER, 31);
+ Date d = new Date(2003 - 1900, OCTOBER, 31);
cal.setTime(d);
cal.set(DAY_OF_WEEK, SUNDAY);
cal.set(2003, OCTOBER, 31); // 2003/10/31 is Friday.
- backported by
-
JDK-8334288 Unintentional use of new Date(year...) with absolute year
-
- Resolved
-
-
JDK-8340725 Unintentional use of new Date(year...) with absolute year
-
- Resolved
-
-
JDK-8343899 Unintentional use of new Date(year...) with absolute year
-
- Resolved
-
- links to
-
Commit(master) openjdk/jdk11u-dev/04e6f37d
-
Review(master) openjdk/jdk11u-dev/2924