From b30c75be40d34fc844424f8fc5a71eb3fa55b6e0 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 31 Jan 2023 23:24:30 +0100 Subject: [PATCH 1/2] Fix unused exception error-prone warning Ignoring the exception seems intended in this case. Change-Id: I9dedf61b9cb5a6ff39fb141dd5da19143f4f6978 --- .../org/eclipse/jgit/internal/storage/file/LooseObjects.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LooseObjects.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LooseObjects.java index b9af83d24..326c5f645 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LooseObjects.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LooseObjects.java @@ -254,7 +254,7 @@ long getSize(WindowCursor curs, AnyObjectId id) throws IOException { // refresh directory to work around NFS caching issue } return getSizeWithoutRefresh(curs, id); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException unused) { if (fileFor(id).exists()) { throw noFile; } From 9dfd2ff665e24453500bf823132f4da760617b05 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 31 Jan 2023 23:23:44 +0100 Subject: [PATCH 2/2] Avoid error-prone warning GC.gc() returns a Future, which should not be discarded. See also https://errorprone.info/bugpattern/FutureReturnValueIgnored Change-Id: I343cc3cfe74a564ad7f8d53f0fe9d96a23aaed00 --- .../jgit/internal/storage/file/GcCommitGraphTest.java | 10 +++++----- .../internal/storage/file/ObjectDirectoryTest.java | 8 ++++---- .../eclipse/jgit/revwalk/RevWalkCommitGraphTest.java | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java index 358e19ef6..dbc9dba2c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java @@ -90,7 +90,7 @@ public void testWriteWhenGc() throws Exception { bb.update(tip); assertTrue(gc.shouldWriteCommitGraphWhenGc()); - gc.gc(); + gc.gc().get(); File graphFile = new File(repo.getObjectsDirectory(), Constants.INFO_COMMIT_GRAPH); assertGraphFile(graphFile); @@ -103,7 +103,7 @@ public void testDefaultWriteWhenGc() throws Exception { bb.update(tip); assertFalse(gc.shouldWriteCommitGraphWhenGc()); - gc.gc(); + gc.gc().get(); File graphFile = new File(repo.getObjectsDirectory(), Constants.INFO_COMMIT_GRAPH); assertFalse(graphFile.exists()); @@ -123,21 +123,21 @@ public void testDisableWriteWhenGc() throws Exception { config.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, true); - gc.gc(); + gc.gc().get(); assertFalse(graphFile.exists()); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_COMMIT_GRAPH, true); config.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, false); - gc.gc(); + gc.gc().get(); assertFalse(graphFile.exists()); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_COMMIT_GRAPH, false); config.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, false); - gc.gc(); + gc.gc().get(); assertFalse(graphFile.exists()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java index ddc4a9d0b..d74766dbf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java @@ -247,7 +247,7 @@ public void testWindowCursorGetCommitGraph() throws Exception { assertTrue(curs.getCommitGraph().isEmpty()); commitFile("file.txt", "content", "master"); GC gc = new GC(db); - gc.gc(); + gc.gc().get(); assertTrue(curs.getCommitGraph().isPresent()); db.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, @@ -286,7 +286,7 @@ public void testGetCommitGraph() throws Exception { // add commit-graph commitFile("file.txt", "content", "master"); GC gc = new GC(db); - gc.gc(); + gc.gc().get(); File file = new File(db.getObjectsDirectory(), Constants.INFO_COMMIT_GRAPH); assertTrue(file.exists()); @@ -296,7 +296,7 @@ public void testGetCommitGraph() throws Exception { // update commit-graph commitFile("file2.txt", "content", "master"); - gc.gc(); + gc.gc().get(); assertEquals(2, dir.getCommitGraph().get().getCommitCnt()); // delete commit-graph @@ -311,7 +311,7 @@ public void testGetCommitGraph() throws Exception { assertTrue(dir.getCommitGraph().isEmpty()); // add commit-graph again - gc.gc(); + gc.gc().get(); assertTrue(dir.getCommitGraph().isPresent()); assertEquals(2, dir.getCommitGraph().get().getCommitCnt()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java index 05e023bb7..6c8014513 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java @@ -309,7 +309,7 @@ void enableAndWriteCommitGraph() throws Exception { db.getConfig().setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, true); GC gc = new GC(db); - gc.gc(); + gc.gc().get(); } private void reinitializeRevWalk() {