Close JarFile when finding main class from archive

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 gh-50949

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
This commit is contained in:
Sebastien Tardif
2026-07-16 11:08:06 +02:00
committed by Stéphane Nicoll
parent f01e775082
commit c3153dc39f
@@ -71,8 +71,9 @@ public class FindMainClass extends Task {
if (this.classesRoot.isDirectory()) {
return MainClassFinder.findSingleMainClass(this.classesRoot, SPRING_BOOT_APPLICATION_CLASS_NAME);
}
return MainClassFinder.findSingleMainClass(new JarFile(this.classesRoot), "/",
SPRING_BOOT_APPLICATION_CLASS_NAME);
try (JarFile jarFile = new JarFile(this.classesRoot)) {
return MainClassFinder.findSingleMainClass(jarFile, "/", SPRING_BOOT_APPLICATION_CLASS_NAME);
}
}
catch (IOException ex) {
throw new BuildException(ex);