Skip to content

Commit

Permalink
8247706: Unintentional use of new Date(year...) with absolute year
Browse files Browse the repository at this point in the history
Reviewed-by: naoto, rriggs
  • Loading branch information
Martin Buchholz committed Jun 17, 2020
1 parent 4f2edac commit 175b597
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1067,7 +1067,7 @@ public void Test4261506() {
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");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -180,7 +180,7 @@ Object[][] data_time() {
@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);
Expand All @@ -192,7 +192,7 @@ public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyle
@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);
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/java/util/Calendar/FieldStateTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -147,7 +147,7 @@ public void TestFieldState() {
+ "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.
Expand Down

0 comments on commit 175b597

Please sign in to comment.