Skip to content

Commit 3cafe9b

Browse files
committed
Merge pull request #50626 from SebTardif
* fix/architecture-check-classloader-leak: Close URLClassLoader in ArchitectureCheck Closes gh-50626
2 parents a009ea4 + 6d9fd88 commit 3cafe9b

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,18 @@ private Stream<EvaluationResult> evaluate(JavaClasses javaClasses) {
132132

133133
private void withCompileClasspath(Callable<?> callable) throws Exception {
134134
ClassLoader previous = Thread.currentThread().getContextClassLoader();
135-
try {
136-
List<URL> urls = new ArrayList<>();
137-
for (File file : getCompileClasspath().getFiles()) {
138-
urls.add(file.toURI().toURL());
139-
}
140-
ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader());
141-
Thread.currentThread().setContextClassLoader(classLoader);
142-
callable.call();
135+
List<URL> urls = new ArrayList<>();
136+
for (File file : getCompileClasspath().getFiles()) {
137+
urls.add(file.toURI().toURL());
143138
}
144-
finally {
145-
Thread.currentThread().setContextClassLoader(previous);
139+
try (URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader())) {
140+
Thread.currentThread().setContextClassLoader(classLoader);
141+
try {
142+
callable.call();
143+
}
144+
finally {
145+
Thread.currentThread().setContextClassLoader(previous);
146+
}
146147
}
147148
}
148149

0 commit comments

Comments
 (0)