Fix JavaTimeDefaultTimeZone error flagged by error prone
Running recent error prone version complaining on that code:
TimeMachine.java:54: error: [JavaTimeDefaultTimeZone] Clock.systemDefaultZone()
is not allowed because it silently uses the system default time-zone.
You must pass an explicit time-zone (e.g., ZoneId.of("America/Los_Angeles")
to this method.
clock = Clock.systemDefaultZone();
^
(see https://errorprone.info/bugpattern/JavaTimeDefaultTimeZone)
Bug: Issue 12677
Change-Id: I10e34bf90d1903aeb40810509b87b0519971ade1
diff --git a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/TimeMachine.java b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/TimeMachine.java
index c4fe5c0..53241ac 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/deleteproject/TimeMachine.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/deleteproject/TimeMachine.java
@@ -26,7 +26,8 @@
*/
public class TimeMachine {
- private static Clock clock = Clock.systemDefaultZone();
+ private static ZoneId PACIFIC_TIME_ZONE = ZoneId.of("America/Los_Angeles");
+ private static Clock clock = Clock.system(PACIFIC_TIME_ZONE);
/**
* Obtain the current instant on the time-line from the system clock using the system default time
@@ -45,12 +46,12 @@
*/
@VisibleForTesting
public static void useFixedClockAt(Instant instant) {
- clock = Clock.fixed(instant, ZoneId.systemDefault());
+ clock = Clock.fixed(instant, PACIFIC_TIME_ZONE);
}
- /** Reset the clock to be the system default. */
+ /** Reset the clock to be the system PCT. */
@VisibleForTesting
- public static void useSystemDefaultZoneClock() {
- clock = Clock.systemDefaultZone();
+ public static void useSystemPctZoneClock() {
+ clock = Clock.system(PACIFIC_TIME_ZONE);
}
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/deleteproject/fs/ArchiveRepositoryRemoverTest.java b/src/test/java/com/googlesource/gerrit/plugins/deleteproject/fs/ArchiveRepositoryRemoverTest.java
index 64634b9..e94390c 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/deleteproject/fs/ArchiveRepositoryRemoverTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/deleteproject/fs/ArchiveRepositoryRemoverTest.java
@@ -101,7 +101,7 @@
PLUGIN_NAME, archiveRepo));
assertDirectoryContents(archiveRepo, true);
} finally {
- TimeMachine.useSystemDefaultZoneClock();
+ TimeMachine.useSystemPctZoneClock();
}
}