Skip to content

Commit 1468585

Browse files
committed
Synchronize on class loading lock in RestartClassLoader
Closes gh-12171
1 parent 413847c commit 1468585

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoader.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -142,19 +142,21 @@ public Class<?> loadClass(String name, boolean resolve)
142142
if (file != null && file.getKind() == Kind.DELETED) {
143143
throw new ClassNotFoundException(name);
144144
}
145-
Class<?> loadedClass = findLoadedClass(name);
146-
if (loadedClass == null) {
147-
try {
148-
loadedClass = findClass(name);
145+
synchronized (getClassLoadingLock(name)) {
146+
Class<?> loadedClass = findLoadedClass(name);
147+
if (loadedClass == null) {
148+
try {
149+
loadedClass = findClass(name);
150+
}
151+
catch (ClassNotFoundException ex) {
152+
loadedClass = getParent().loadClass(name);
153+
}
149154
}
150-
catch (ClassNotFoundException ex) {
151-
loadedClass = getParent().loadClass(name);
155+
if (resolve) {
156+
resolveClass(loadedClass);
152157
}
158+
return loadedClass;
153159
}
154-
if (resolve) {
155-
resolveClass(loadedClass);
156-
}
157-
return loadedClass;
158160
}
159161

160162
@Override

0 commit comments

Comments
 (0)