Skip to content

Commit 6d9fd88

Browse files
SebTardifsnicoll
authored andcommitted
Close URLClassLoader in ArchitectureCheck
See gh-50626 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent a009ea4 commit 6d9fd88

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)