From c67393562be7e3db0e39cb2d3ff5f8192e2f2cd5 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Wed, 13 Nov 2024 16:25:42 -0800 Subject: [PATCH] SystemReader#now: make it a concrete method Abstract methods break subclasses (e.g. DelegateSystemReader in gerrit). Updating jgit and gerrit is simpler if we do not add them. I am not sure why some methods are abstract and others dont, but now() can be a concrete method. Make now() concrete. Implement it by default based on getCurrentTime(), so subclasses overriding that method get the same value. Change-Id: I697749f8cba698c5388ed13ebdc2b238d6259358 --- .../src/org/eclipse/jgit/junit/MockSystemReader.java | 6 ------ .../src/org/eclipse/jgit/util/SystemReader.java | 6 +++++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java index bf236ab17d..38f0d0b2cb 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java @@ -18,7 +18,6 @@ import java.lang.reflect.Field; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.Duration; -import java.time.Instant; import java.time.ZoneId; import java.time.ZoneOffset; import java.util.HashMap; @@ -204,11 +203,6 @@ public class MockSystemReader extends SystemReader { return now; } - @Override - public Instant now() { - return Instant.ofEpochMilli(now); - } - @Override public MonotonicClock getClock() { return () -> { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java index 18b0e152c9..7cdf0ee1a2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -532,7 +532,11 @@ public abstract class SystemReader { * * @since 7.1 */ - public abstract Instant now(); + public Instant now() { + // Subclasses overriding getCurrentTime should keep working + // TODO(ifrade): Once we remove getCurrentTime, use Instant.now() + return Instant.ofEpochMilli(getCurrentTime()); + } /** * Get clock instance preferred by this system. -- 2.39.5