Skip to content

Commit

Permalink
Increase year range on Date usages.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 612829610
  • Loading branch information
kluever authored and Error Prone Team committed Mar 5, 2024
1 parent ad513d5 commit 3292632
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public final class DateChecker extends BugChecker
private static final Matcher<ExpressionTree> SET_SEC =
instanceMethod().onExactClass(DATE).named("setSeconds");

// permits years [1901, 2050] which seems ~reasonable
private static final Range<Integer> YEAR_RANGE = Range.closed(1, 150);
// permits years [1901, 2200] which seems ~reasonable
private static final Range<Integer> YEAR_RANGE = Range.closed(1, 300);
private static final Range<Integer> MONTH_RANGE = Range.closed(0, 11);
private static final Range<Integer> DAY_RANGE = Range.closed(1, 31);
private static final Range<Integer> HOUR_RANGE = Range.closed(0, 23);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ public void constructor_allBad() {
"import java.util.Date;",
"public class TestClass {",
" // BUG: Diagnostic contains: "
+ "The 1900-based year value (2020) is out of bounds [1..150]. "
+ "The 1900-based year value (2020) is out of bounds [1..300]. "
+ "The 0-based month value (13) is out of bounds [0..11].",
" Date bad1 = new Date(2020, 13, 31);",
" // BUG: Diagnostic contains: "
+ "The 1900-based year value (2020) is out of bounds [1..150]. "
+ "The 1900-based year value (2020) is out of bounds [1..300]. "
+ "The 0-based month value (13) is out of bounds [0..11]. "
+ "The hours value (-2) is out of bounds [0..23]. "
+ "The minutes value (61) is out of bounds [0..59].",
" Date bad2 = new Date(2020, 13, 31, -2, 61);",
" // BUG: Diagnostic contains: "
+ "The 1900-based year value (2020) is out of bounds [1..150]. "
+ "The 1900-based year value (2020) is out of bounds [1..300]. "
+ "The 0-based month value (13) is out of bounds [0..11]. "
+ "The hours value (-2) is out of bounds [0..23]. "
+ "The minutes value (61) is out of bounds [0..59]. "
Expand All @@ -165,7 +165,7 @@ public void constructor_badYear() {
"import java.util.Date;",
"public class TestClass {",
" // BUG: Diagnostic contains: "
+ "The 1900-based year value (2020) is out of bounds [1..150].",
+ "The 1900-based year value (2020) is out of bounds [1..300].",
" Date bad = new Date(2020, JULY, 10);",
"}")
.doTest();
Expand Down Expand Up @@ -222,7 +222,7 @@ public void setters_good() {
" public void foo(Date date) {",
" date.setYear(1);",
" date.setYear(120);",
" date.setYear(150);",
" date.setYear(300);",
" date.setMonth(JANUARY);",
" date.setMonth(FEBRUARY);",
" date.setMonth(MARCH);",
Expand Down Expand Up @@ -261,13 +261,13 @@ public void setters_badYears() {
"public class TestClass {",
" public void foo(Date date) {",
" // BUG: Diagnostic contains: "
+ "The 1900-based year value (0) is out of bounds [1..150].",
+ "The 1900-based year value (0) is out of bounds [1..300].",
" date.setYear(0);",
" // BUG: Diagnostic contains: "
+ "The 1900-based year value (-1) is out of bounds [1..150].",
+ "The 1900-based year value (-1) is out of bounds [1..300].",
" date.setYear(-1);",
" // BUG: Diagnostic contains: "
+ "The 1900-based year value (2020) is out of bounds [1..150].",
+ "The 1900-based year value (2020) is out of bounds [1..300].",
" date.setYear(2020);",
" }",
"}")
Expand Down

0 comments on commit 3292632

Please sign in to comment.