Skip to content

Commit

Permalink
Change ClassLoaderMap to ConcurrentHashMap, re #316
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Jan 16, 2020
1 parent 14b8596 commit 1b47c44
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarFile;

Expand All @@ -51,8 +49,9 @@
public class SpecialAgent extends SpecialAgentBase {
private static final Logger logger = Logger.getLogger(SpecialAgent.class);

private static class ClassLoaderMap<T> extends IdentityHashMap<ClassLoader,T> {
private static class ClassLoaderMap<T> extends ConcurrentHashMap<ClassLoader,T> {
private static final long serialVersionUID = 5515722666603482519L;
private static final ClassLoader NULL = new ClassLoader() {};

/**
* This method is modified to support value lookups where the key is a
Expand All @@ -65,12 +64,17 @@ private static class ClassLoaderMap<T> extends IdentityHashMap<ClassLoader,T> {
@Override
@SuppressWarnings("unlikely-arg-type")
public T get(final Object key) {
T value = super.get(key);
T value = super.get(key == null ? NULL : key);
if (value != null || !(key instanceof URLClassLoader))
return value;

final URLClassLoader classLoader = (URLClassLoader)key;
return classLoader.getURLs().length > 0 || classLoader.getParent() != null ? null : super.get(null);
return classLoader.getURLs().length > 0 || classLoader.getParent() != null ? null : super.get(NULL);
}

@Override
public T put(final ClassLoader key, final T value) {
return super.put(key == null ? NULL : key, value);
}
}

Expand Down Expand Up @@ -186,7 +190,7 @@ static void initialize(final Manager manager) {
final String key = String.valueOf(property.getKey());
final String value = properties.get(key);
if (value != null && !value.equals(property.getValue()))
throw new IllegalStateException("System property " + key + " is specified twice with different values");
throw new IllegalStateException("System property " + key + " is specified twice with different values: \"" + value + "\" and \"" + property.getValue() + "\"");

properties.put(key, property.getValue() == null ? null : String.valueOf(property.getValue()));
}
Expand Down Expand Up @@ -361,7 +365,7 @@ public boolean test(final File file) {
private static URL findTracer(final ClassLoader classLoader, final String name) {
try {
final Enumeration<URL> enumeration = classLoader.getResources(TRACER_FACTORY);
final Set<URL> urls = new HashSet<>();
final HashSet<URL> urls = new HashSet<>();
while (enumeration.hasMoreElements()) {
final URL url = enumeration.nextElement();
if (urls.contains(url))
Expand Down Expand Up @@ -397,7 +401,7 @@ private static int loadDependencies(final ClassLoader classLoader, final Map<Str
int count = 0;
try {
final Enumeration<URL> enumeration = classLoader.getResources(DEPENDENCIES_TGF);
final Set<String> urls = new HashSet<>();
final HashSet<String> urls = new HashSet<>();
while (enumeration.hasMoreElements()) {
final URL url = enumeration.nextElement();
if (urls.contains(url.toString()))
Expand Down

0 comments on commit 1b47c44

Please sign in to comment.