Skip to content

Commit

Permalink
Use IdentityHashMap for all maps and sets (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Jun 2, 2021
1 parent abe57d4 commit 6628929
Showing 1 changed file with 12 additions and 7 deletions.
Expand Up @@ -30,8 +30,8 @@

import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -52,23 +52,28 @@ public class ClassLoaderOrder {
* The set of all {@link ClassLoader} instances that have been added to the order so far, so that classloaders
* don't get added twice.
*/
private final Set<ClassLoader> added = new HashSet<>();
// Need to use IdentityHashMap for maps and sets here, because TomEE weirdly makes instances of
// CxfContainerClassLoader equal to (via .equals()) the instance of TomEEWebappClassLoader that it
// delegates to (#515)
private final Set<ClassLoader> added = Collections.newSetFromMap(new IdentityHashMap<ClassLoader, Boolean>());

/**
* The set of all {@link ClassLoader} instances that have been delegated to so far, to prevent an infinite loop
* in delegation.
*/
private final Set<ClassLoader> delegatedTo = new HashSet<>();
private final Set<ClassLoader> delegatedTo = Collections
.newSetFromMap(new IdentityHashMap<ClassLoader, Boolean>());

/**
* The set of all parent {@link ClassLoader} instances that have been delegated to so far, to enable
* {@link ClassGraph#ignoreParentClassLoaders()}.
*/
private final Set<ClassLoader> allParentClassLoaders = new HashSet<>();
private final Set<ClassLoader> allParentClassLoaders = Collections
.newSetFromMap(new IdentityHashMap<ClassLoader, Boolean>());

/** A map from {@link ClassLoader} to {@link ClassLoaderHandlerRegistryEntry}. */
private final Map<ClassLoader, ClassLoaderHandlerRegistryEntry> classLoaderToClassLoaderHandlerRegistryEntry = //
new HashMap<>();
new IdentityHashMap<ClassLoader, ClassLoaderHandlerRegistryEntry>();

// -------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -130,7 +135,7 @@ private ClassLoaderHandlerRegistryEntry getRegistryEntry(final ClassLoader class
}

/**
* Add a {@link ClassLoader} to the {@link ClassLoader} order at the current position.
* Add a {@link ClassLoader} to the ClassLoader order at the current position.
*
* @param classLoader
* the class loader
Expand Down

0 comments on commit 6628929

Please sign in to comment.