summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2020-12-04 11:12:27 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2020-12-22 10:52:59 +0100
commit39cbc574d177373411052923db25af22f96f25e0 (patch)
treeb34696c7c41397f65e8f7ae7cd6804e156afba1a /org.eclipse.jgit
parent1fd0a49ce05c158e9754a5d9ac0cfbe56f6b65bb (diff)
downloadjgit-39cbc574d177373411052923db25af22f96f25e0.tar.gz
jgit-39cbc574d177373411052923db25af22f96f25e0.zip
[spotbugs] DfsReftableDatabase: extract lock to local variable
This fixes UL_UNRELEASED_LOCK_EXCEPTION_PATH raised by spotbugs in #DfsReftableDatabase and #clearCache. Change-Id: Ifd3189288d2a8e64139c02cd105eb335fa2f68cf Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java
index 8a54431d5c..5561dc6a27 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java
@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jgit.annotations.Nullable;
@@ -62,11 +63,12 @@ public class DfsReftableDatabase extends DfsRefDatabase {
reftableDatabase = new ReftableDatabase() {
@Override
public MergedReftable openMergedReftable() throws IOException {
- DfsReftableDatabase.this.getLock().lock();
+ Lock l = DfsReftableDatabase.this.getLock();
+ l.lock();
try {
return new MergedReftable(stack().readers());
} finally {
- DfsReftableDatabase.this.getLock().unlock();
+ l.unlock();
}
}
};
@@ -207,7 +209,8 @@ public class DfsReftableDatabase extends DfsRefDatabase {
@Override
void clearCache() {
- getLock().lock();
+ ReentrantLock l = getLock();
+ l.lock();
try {
if (ctx != null) {
ctx.close();
@@ -219,7 +222,7 @@ public class DfsReftableDatabase extends DfsRefDatabase {
stack = null;
}
} finally {
- getLock().unlock();
+ l.unlock();
}
}