From 11ddaff6af3e14c9c0d06c29c12a9c1d87669320 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 14 Mar 2018 13:37:44 +0900 Subject: [PATCH] RepositoryCache#registerRepository: Refactor to use try-with-resource Change-Id: Iaad45b66cc10ac267f6aed7999cc8dc8c07f92e6 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/lib/RepositoryCache.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java index ce7ce8cd8..5e902c988 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java @@ -288,9 +288,9 @@ public class RepositoryCache { } private void registerRepository(final Key location, final Repository db) { - Repository oldDb = cacheMap.put(location, db); - if (oldDb != null) - oldDb.close(); + try (Repository oldDb = cacheMap.put(location, db)) { + // oldDb is auto-closed + } } private Repository unregisterRepository(final Key location) {