diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java index 1bda1d207b2..c4426261ff9 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java @@ -26,6 +26,9 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; /** A {@link BugChecker} that flags illegal time-zone related operations. */ @AutoService(BugChecker.class) @@ -58,7 +61,10 @@ public final class TimeZoneUsage extends BugChecker implements MethodInvocationT .onClassAny( LocalDate.class.getName(), LocalDateTime.class.getName(), - LocalTime.class.getName()) + LocalTime.class.getName(), + OffsetDateTime.class.getName(), + OffsetTime.class.getName(), + ZonedDateTime.class.getName()) .named("now"), staticMethod().onClassAny(Instant.class.getName()).named("now").withNoParameters()); diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java index b675225b925..1250fa53493 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java @@ -26,7 +26,10 @@ void identification() { "import java.time.LocalDate;", "import java.time.LocalDateTime;", "import java.time.LocalTime;", + "import java.time.OffsetDateTime;", + "import java.time.OffsetTime;", "import java.time.ZoneId;", + "import java.time.ZonedDateTime;", "", "class A {", " void m() {", @@ -78,6 +81,27 @@ void identification() { " LocalTime.now(clock);", " // BUG: Diagnostic matches: X", " LocalTime.now(UTC);", + "", + " // BUG: Diagnostic matches: X", + " OffsetDateTime.now();", + " // BUG: Diagnostic matches: X", + " OffsetDateTime.now(clock);", + " // BUG: Diagnostic matches: X", + " OffsetDateTime.now(UTC);", + "", + " // BUG: Diagnostic matches: X", + " OffsetTime.now();", + " // BUG: Diagnostic matches: X", + " OffsetTime.now(clock);", + " // BUG: Diagnostic matches: X", + " OffsetTime.now(UTC);", + "", + " // BUG: Diagnostic matches: X", + " ZonedDateTime.now();", + " // BUG: Diagnostic matches: X", + " ZonedDateTime.now(clock);", + " // BUG: Diagnostic matches: X", + " ZonedDateTime.now(UTC);", " }", "", " abstract class ForwardingClock extends Clock {",