Fix JdkObsolete issue with Date
Use Instant instead of Date and format it with a formatter that produces
the same output as 'new Date().toString()'.
Bug: Issue 15070
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I4d22075616050ffbf403857e5517116a70902c01
diff --git a/src/main/java/com/googlesource/gerrit/plugins/manager/FirstWebLoginListener.java b/src/main/java/com/googlesource/gerrit/plugins/manager/FirstWebLoginListener.java
index f0c934c..d7d936f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/manager/FirstWebLoginListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/manager/FirstWebLoginListener.java
@@ -25,7 +25,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
-import java.util.Date;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -55,8 +57,11 @@
if (!firstLoginFile.toFile().exists()) {
response.sendRedirect(pluginUrlPath + "static/intro.html");
- Files.write(
- firstLoginFile, new Date().toString().getBytes(UTF_8), StandardOpenOption.CREATE);
+ String timestamp =
+ DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy")
+ .withZone(ZoneId.systemDefault())
+ .format(Instant.now());
+ Files.write(firstLoginFile, timestamp.getBytes(UTF_8), StandardOpenOption.CREATE);
}
}
}