Close URLClassLoader in ArchitectureCheck#50626
Merged
snicoll merged 1 commit intoMay 30, 2026
Merged
Conversation
nosan
reviewed
May 29, 2026
| try { | ||
| List<URL> urls = new ArrayList<>(); | ||
| for (File file : getCompileClasspath().getFiles()) { | ||
| urls.add(file.toURI().toURL()); | ||
| } | ||
| ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader()); | ||
| classLoader = new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader()); |
Contributor
There was a problem hiding this comment.
I think you can use try-with-resources to make it a little bit better.
try (URLClassLoader classLoader = new URLClassLoader(...)) {
Thread.currentThread().setContextClassLoader(classLoader);
callable.call();
}
finally {
Thread.currentThread().setContextClassLoader(previous);
}
Contributor
|
I think your target branch should be 3.5.x, not main, since all branches are affected. |
c294df5 to
5940265
Compare
Contributor
Author
|
Thanks @nosan for the review!
Verified locally:
The updated commit is on the branch. |
5940265 to
e699659
Compare
See spring-projectsgh-50626 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
e699659 to
6d9fd88
Compare
Member
|
Thanks @nosan, I had the same thoughts when I had a quick look but I meant to polish in that direction. Thanks @SebTardif for following up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
URLClassLoader implements Closeable but was never closed in
withCompileClasspath(), leaking JAR file handles in long-runningGradle daemon processes.
The fix declares the classloader before the try block and closes it
in the finally block after restoring the original context classloader.