JarFile is not closed when finding main class from archive#50949
Merged
snicoll merged 1 commit intoJul 16, 2026
Conversation
Member
|
@SebTardif thanks again. I have a feeling you open a new PR every time one gets closed. This back and forth is quite time consuming on our end. Can't we gather stream cleanup in an issue rather than creating so many different PRs? I am asking if you have piled up more changes. |
Contributor
Author
|
@snicoll No further stream/resource cleanup changes are lined up. |
Member
|
@SebTardif did you mean to close this one? |
MainClassFinder.findSingleMainClass(JarFile, ...) does not close the JarFile; the caller owns the resource. FindMainClass passed a newly opened JarFile without closing it, unlike sibling call sites that use try-with-resources. See spring-projectsgh-50949 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
snicoll
force-pushed
the
fix/findmainclass-close-jarfile
branch
from
July 16, 2026 09:08
a7a5011 to
c3153dc
Compare
Member
|
@SebTardif while I appreciate taking the time to write a test for this, I don't think it is worth it considering the change and the additional librairies the test brings. Thanks again for the PR! |
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.
What Problem This Solves
FindMainClassopens aJarFilewhen@classesRootpoints at an archive and passes it toMainClassFinder.findSingleMainClass(JarFile, ...). That API does not close the jar; the caller owns the resource. The Ant task never closed it, leaving a file handle open for the rest of the JVM lifetime (or until GC finalization).Almost every other
new JarFile(...)call site in this repository already uses try-with-resources (Gradle/Maven plugins, loader tools, buildSrc checks, etc.).Evidence
Red-green unit proof:
Also verified:
checkFormatMain/checkFormatTest,checkstyleMain/checkstyleTest.Summary
Wrap the archive path in try-with-resources so the jar is closed after the main-class search returns.
Related
FindMainClassin1595286e04(2016-11-29; preferred@SpringBootApplicationsearch). The unclosednew JarFilepattern has been present since the Ant task gained jar support.Test plan
FindMainClassTests.closesJarFileWhenSearchingArchivefails without close