]> source.dussan.org Git - jgit.git/commitdiff
[spotbugs] DfsReftableDatabase: extract lock to local variable 75/173375/7
authorMatthias Sohn <matthias.sohn@sap.com>
Fri, 4 Dec 2020 10:12:27 +0000 (11:12 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 22 Dec 2020 09:52:59 +0000 (10:52 +0100)
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>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java

index 8a54431d5c8e5081160d0665887462c84333336e..5561dc6a2713adce2b8420f7bd694da7dc8a1fdb 100644 (file)
@@ -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();
                }
        }