From 0f442d70836ee292ed916605448f806cc7d1fe78 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Wed, 30 Dec 2020 17:17:44 +0100 Subject: [PATCH] Use Map interface instead of ConcurrentHashMap class On Android, the co-variant override of ConcurrentHashMap.keySet() introduced in Java 8 was undone. [1] If compiled Java code calls that co-variant override directly, one gets a NoSuchMethodError exception at run-time on Android. Making the code call that method via Map.keySet() side-steps this problem. This is similar to bug 496262, where the same problem cropped up when compiling with Java 8 against a Java 7 target, but here we cannot use bootclasspath. We build against Java 8, not against the Android version of it. Recent Android versions should have some bytecode "magic" that adds the co-variant override in bytecode (see the commit referenced in [1]), but on older Android version this problem may still occur. (Or perhaps the "magic" is ineffective...) There are two pull requests on Github for this problem, both from 2020, [2][3] while the Android commit [1] is from March 2018. Apparently people still occasionally run into this problem in the wild. [1] https://android.googlesource.com/platform/libcore/+/0e8b937ded4de39f1d1cea5f04800d67dd2ec570/ojluni/src/main/java/java/util/concurrent/ConcurrentHashMap.java#1244 [2] https://github.com/eclipse/jgit/pull/104 [3] https://github.com/eclipse/jgit/pull/100 Change-Id: I7c07e0cc59871cb7fe60795e22867827fa9c2458 Signed-off-by: Thomas Wolf --- .../src/org/eclipse/jgit/junit/http/AppServer.java | 4 ++-- .../src/org/eclipse/jgit/api/ArchiveCommand.java | 5 ++--- .../org/eclipse/jgit/attributes/FilterCommandRegistry.java | 3 ++- .../src/org/eclipse/jgit/events/ListenerList.java | 4 ++-- .../src/org/eclipse/jgit/lib/RepositoryCache.java | 3 ++- org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java | 4 +++- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java index 4e27a3d35..f9f8c856b 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/AppServer.java @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.security.AbstractLoginService; @@ -259,7 +259,7 @@ public ServletContextHandler authBasic(ServletContextHandler ctx, static class TestMappedLoginService extends AbstractLoginService { private String role; - protected final ConcurrentMap users = new ConcurrentHashMap<>(); + protected final Map users = new ConcurrentHashMap<>(); TestMappedLoginService(String role) { this.role = role; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java index 2c01c19c5..fdf8b80cd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; @@ -202,7 +201,7 @@ public FormatEntry(Format format, int refcnt) { * Available archival formats (corresponding to values for * the --format= option) */ - private static final ConcurrentMap formats = + private static final Map formats = new ConcurrentHashMap<>(); /** @@ -215,7 +214,7 @@ public FormatEntry(Format format, int refcnt) { * @param newValue value to be associated with the key (null to remove). * @return true if the value was replaced */ - private static boolean replace(ConcurrentMap map, + private static boolean replace(Map map, K key, V oldValue, V newValue) { if (oldValue == null && newValue == null) // Nothing to do. return true; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java index 2698e2303..1c9e9d7f7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -23,7 +24,7 @@ * @since 4.6 */ public class FilterCommandRegistry { - private static ConcurrentHashMap filterCommandRegistry = new ConcurrentHashMap<>(); + private static Map filterCommandRegistry = new ConcurrentHashMap<>(); /** * Register a {@link org.eclipse.jgit.attributes.FilterCommandFactory} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/events/ListenerList.java b/org.eclipse.jgit/src/org/eclipse/jgit/events/ListenerList.java index 32c3a1d28..476c37c1c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/events/ListenerList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/events/ListenerList.java @@ -11,15 +11,15 @@ package org.eclipse.jgit.events; import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; /** * Manages a thread-safe list of {@link org.eclipse.jgit.events.RepositoryListener}s. */ public class ListenerList { - private final ConcurrentMap, CopyOnWriteArrayList> lists = new ConcurrentHashMap<>(); + private final Map, CopyOnWriteArrayList> lists = new ConcurrentHashMap<>(); /** * Register a {@link org.eclipse.jgit.events.WorkingTreeModifiedListener}. 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 2c108de86..c1beb6f41 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -193,7 +194,7 @@ static void reconfigure(RepositoryCacheConfig repositoryCacheConfig) { cache.configureEviction(repositoryCacheConfig); } - private final ConcurrentHashMap cacheMap; + private final Map cacheMap; private final Lock[] openLocks; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java b/org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java index d7dd3bee5..881873de6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/nls/NLS.java @@ -11,6 +11,7 @@ package org.eclipse.jgit.nls; import java.util.Locale; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jgit.errors.TranslationBundleLoadingException; @@ -110,7 +111,8 @@ public static void clear() { } private final Locale locale; - private final ConcurrentHashMap map = new ConcurrentHashMap<>(); + + private final Map map = new ConcurrentHashMap<>(); private NLS(Locale locale) { this.locale = locale;