From 3292632ee5f2776b57171bedef6bdb1c4c222345 Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Tue, 5 Mar 2024 07:10:52 -0800 Subject: [PATCH] Increase year range on `Date` usages. PiperOrigin-RevId: 612829610 --- .../errorprone/bugpatterns/time/DateChecker.java | 4 ++-- .../bugpatterns/time/DateCheckerTest.java | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/time/DateChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/time/DateChecker.java index a53a7978d74..3a8d52be84d 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/time/DateChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/time/DateChecker.java @@ -84,8 +84,8 @@ public final class DateChecker extends BugChecker private static final Matcher SET_SEC = instanceMethod().onExactClass(DATE).named("setSeconds"); - // permits years [1901, 2050] which seems ~reasonable - private static final Range YEAR_RANGE = Range.closed(1, 150); + // permits years [1901, 2200] which seems ~reasonable + private static final Range YEAR_RANGE = Range.closed(1, 300); private static final Range MONTH_RANGE = Range.closed(0, 11); private static final Range DAY_RANGE = Range.closed(1, 31); private static final Range HOUR_RANGE = Range.closed(0, 23); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/time/DateCheckerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/time/DateCheckerTest.java index 62eb6eab8f1..bf5caa3c3aa 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/time/DateCheckerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/time/DateCheckerTest.java @@ -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]. " @@ -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(); @@ -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);", @@ -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);", " }", "}")