Make fsTick() robust to coarse on-write timestamps RepositoryTestCase.fsTick() advanced its probe file with FileUtils.touch(), which ends by setting the modification time explicitly via utimensat. On a filesystem whose kernel assigns coarse (for example ~1 ms) timestamps on real writes, such as ext4 with CONFIG_HZ=1000, that explicit set can report an advance the next ordinary write does not honor: the write lands in the same coarse tick as the reference, so an index entry written after fsTick() is not strictly newer than the work file and racy-git smudges it to length 0. The flaw is pre-existing. On the measured Linux host, sub-millisecond Thread.sleep() returned much sooner with Java 21 and 25 than with Java 17: Java 17's longer sleep happened to cross a coarse tick and mask the race, while the shorter sleeps on Java 21 and 25 return within the same tick and expose it reliably. This surfaces four timestamp-sensitive core tests (RacyGitTests, FilterCommandsTest, GcPruneNonReferencedTest, FSTest) as failures under Java 25 on ext4. Advance the probe with a genuine non-empty write instead, polling until the filesystem's own modification time exceeds the reference. This observes the real on-write granularity and holds the "strictly newer" contract on coarse and fine filesystems alike, independent of Thread.sleep() granularity. Exercised under Java 17, 21 and 25 on Ubuntu 24.04.5 LTS (kernel 6.8.0-138-generic, ext4), the real-write polling produced a strictly newer on-write timestamp on every trial. The four affected tests pass under Java 25. Change-Id: I546b3595b46500cd7ed1ce1e216439817014e078
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java index 3a283ce..690ce00 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
@@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.file.Files; import java.nio.file.Path; import java.time.Instant; import java.util.List; @@ -384,7 +385,11 @@ public static Instant fsTick(File lastFile) Instant actTime = fs.lastModifiedInstant(tmp); while (actTime.compareTo(startTime) <= 0) { TimeUnit.NANOSECONDS.sleep(sleepTime); - FileUtils.touch(tmp.toPath()); + // advance the clock with a real write. Setting the mtime + // explicitly (as FileUtils.touch does) can report an advance + // the next ordinary write does not honor on coarse-granularity + // filesystems, breaking fsTick's "strictly newer" contract. + Files.write(tmp.toPath(), new byte[] { 1 }); actTime = fs.lastModifiedInstant(tmp); } return actTime;