Synchronize on class loading lock in RestartClassLoader

Closes gh-12171
This commit is contained in:
Andy Wilkinson
2018-02-23 15:04:57 +00:00
parent 413847c72d
commit 146858505f

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -142,19 +142,21 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
if (file != null && file.getKind() == Kind.DELETED) {
throw new ClassNotFoundException(name);
}
Class<?> loadedClass = findLoadedClass(name);
if (loadedClass == null) {
try {
loadedClass = findClass(name);
synchronized (getClassLoadingLock(name)) {
Class<?> loadedClass = findLoadedClass(name);
if (loadedClass == null) {
try {
loadedClass = findClass(name);
}
catch (ClassNotFoundException ex) {
loadedClass = getParent().loadClass(name);
}
}
catch (ClassNotFoundException ex) {
loadedClass = getParent().loadClass(name);
if (resolve) {
resolveClass(loadedClass);
}
return loadedClass;
}
if (resolve) {
resolveClass(loadedClass);
}
return loadedClass;
}
@Override