Skip to content

Commit da3cee9

Browse files
committed
Avoid locking entire class loader.
1 parent e597414 commit da3cee9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoader.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,20 +1346,20 @@ public Enumeration<URL> getResources(String name) throws IOException {
13461346
/**
13471347
* Checks if a resource name represents a class file of a class that was loaded by this class loader.
13481348
*
1349-
* @param resourceName The resource name of the class to be exposed as its class file.
1349+
* @param resource The resource name of the class to be exposed as its class file.
13501350
* @return {@code true} if this class represents a class that is being loaded by this class loader.
13511351
*/
1352-
private boolean isShadowed(String resourceName) {
1353-
if (persistenceHandler.isManifest() || !resourceName.endsWith(CLASS_FILE_SUFFIX)) {
1352+
private boolean isShadowed(String resource) {
1353+
if (persistenceHandler.isManifest() || !resource.endsWith(CLASS_FILE_SUFFIX)) {
13541354
return false;
13551355
}
13561356
// This synchronization is required to avoid a racing condition to the actual class loading.
1357-
synchronized (this) {
1358-
String typeName = resourceName.replace('/', '.').substring(0, resourceName.length() - CLASS_FILE_SUFFIX.length());
1359-
if (typeDefinitions.containsKey(typeName)) {
1357+
String name = resource.replace('/', '.').substring(0, resource.length() - CLASS_FILE_SUFFIX.length());
1358+
synchronized (SYNCHRONIZATION_STRATEGY.initialize().getClassLoadingLock(this, name)) {
1359+
if (typeDefinitions.containsKey(name)) {
13601360
return true;
13611361
}
1362-
Class<?> loadedClass = findLoadedClass(typeName);
1362+
Class<?> loadedClass = findLoadedClass(name);
13631363
return loadedClass != null && loadedClass.getClassLoader() == this;
13641364
}
13651365
}

0 commit comments

Comments
 (0)