From d67ac798f10254d038c49244e7f1e2323afdfdfc Mon Sep 17 00:00:00 2001 From: "James Z.M. Gao" Date: Fri, 8 Apr 2022 00:29:39 +0800 Subject: Remove stray files (probes or lock files) created by background threads NOTE: port back from master branch. On process exit, it was possible that the filesystem timestamp resolution measurement left behind .probe files or even a lock file for the jgit.config. Ensure the SAVE_RUNNER is shut down when the process exits (via System.exit() or otherwise). Move lf.lock() into the try-finally block when saving the config file. Delete .probe files on JVM shutdown -- they are created in daemon threads that may terminate abruptly, not executing the "finally" clause that normally removes these files. Bug: 579445 Change-Id: Iaee2301eb14e6201406398a90228ad10cfea6098 --- .../org/eclipse/jgit/internal/storage/file/LockFileTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'org.eclipse.jgit.test') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java index 509935dfb9..7eab1dcb09 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java @@ -200,4 +200,16 @@ public class LockFileTest extends RepositoryTestCase { assertFalse(lock.isLocked()); checkFile(f, "contentother"); } + + @Test + public void testUnlockNoop() throws Exception { + File f = writeTrashFile("somefile", "content"); + try { + LockFile lock = new LockFile(f); + lock.unlock(); + lock.unlock(); + } catch (Throwable e) { + fail("unlock should be noop if not locked at all."); + } + } } -- cgit v1.2.3