Skip to content

Commit 3292632

Browse files
klueverError Prone Team
authored and
Error Prone Team
committed
Increase year range on Date usages.
PiperOrigin-RevId: 612829610
1 parent ad513d5 commit 3292632

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/time/DateChecker.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public final class DateChecker extends BugChecker
8484
private static final Matcher<ExpressionTree> SET_SEC =
8585
instanceMethod().onExactClass(DATE).named("setSeconds");
8686

87-
// permits years [1901, 2050] which seems ~reasonable
88-
private static final Range<Integer> YEAR_RANGE = Range.closed(1, 150);
87+
// permits years [1901, 2200] which seems ~reasonable
88+
private static final Range<Integer> YEAR_RANGE = Range.closed(1, 300);
8989
private static final Range<Integer> MONTH_RANGE = Range.closed(0, 11);
9090
private static final Range<Integer> DAY_RANGE = Range.closed(1, 31);
9191
private static final Range<Integer> HOUR_RANGE = Range.closed(0, 23);

core/src/test/java/com/google/errorprone/bugpatterns/time/DateCheckerTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,17 @@ public void constructor_allBad() {
136136
"import java.util.Date;",
137137
"public class TestClass {",
138138
" // BUG: Diagnostic contains: "
139-
+ "The 1900-based year value (2020) is out of bounds [1..150]. "
139+
+ "The 1900-based year value (2020) is out of bounds [1..300]. "
140140
+ "The 0-based month value (13) is out of bounds [0..11].",
141141
" Date bad1 = new Date(2020, 13, 31);",
142142
" // BUG: Diagnostic contains: "
143-
+ "The 1900-based year value (2020) is out of bounds [1..150]. "
143+
+ "The 1900-based year value (2020) is out of bounds [1..300]. "
144144
+ "The 0-based month value (13) is out of bounds [0..11]. "
145145
+ "The hours value (-2) is out of bounds [0..23]. "
146146
+ "The minutes value (61) is out of bounds [0..59].",
147147
" Date bad2 = new Date(2020, 13, 31, -2, 61);",
148148
" // BUG: Diagnostic contains: "
149-
+ "The 1900-based year value (2020) is out of bounds [1..150]. "
149+
+ "The 1900-based year value (2020) is out of bounds [1..300]. "
150150
+ "The 0-based month value (13) is out of bounds [0..11]. "
151151
+ "The hours value (-2) is out of bounds [0..23]. "
152152
+ "The minutes value (61) is out of bounds [0..59]. "
@@ -165,7 +165,7 @@ public void constructor_badYear() {
165165
"import java.util.Date;",
166166
"public class TestClass {",
167167
" // BUG: Diagnostic contains: "
168-
+ "The 1900-based year value (2020) is out of bounds [1..150].",
168+
+ "The 1900-based year value (2020) is out of bounds [1..300].",
169169
" Date bad = new Date(2020, JULY, 10);",
170170
"}")
171171
.doTest();
@@ -222,7 +222,7 @@ public void setters_good() {
222222
" public void foo(Date date) {",
223223
" date.setYear(1);",
224224
" date.setYear(120);",
225-
" date.setYear(150);",
225+
" date.setYear(300);",
226226
" date.setMonth(JANUARY);",
227227
" date.setMonth(FEBRUARY);",
228228
" date.setMonth(MARCH);",
@@ -261,13 +261,13 @@ public void setters_badYears() {
261261
"public class TestClass {",
262262
" public void foo(Date date) {",
263263
" // BUG: Diagnostic contains: "
264-
+ "The 1900-based year value (0) is out of bounds [1..150].",
264+
+ "The 1900-based year value (0) is out of bounds [1..300].",
265265
" date.setYear(0);",
266266
" // BUG: Diagnostic contains: "
267-
+ "The 1900-based year value (-1) is out of bounds [1..150].",
267+
+ "The 1900-based year value (-1) is out of bounds [1..300].",
268268
" date.setYear(-1);",
269269
" // BUG: Diagnostic contains: "
270-
+ "The 1900-based year value (2020) is out of bounds [1..150].",
270+
+ "The 1900-based year value (2020) is out of bounds [1..300].",
271271
" date.setYear(2020);",
272272
" }",
273273
"}")

0 commit comments

Comments
 (0)