Skip to content

Commit c3153dc

Browse files
SebTardifsnicoll
authored andcommitted
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>
1 parent f01e775 commit c3153dc

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • build-plugin/spring-boot-antlib/src/main/java/org/springframework/boot/ant

build-plugin/spring-boot-antlib/src/main/java/org/springframework/boot/ant/FindMainClass.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ public void execute() throws BuildException {
7171
if (this.classesRoot.isDirectory()) {
7272
return MainClassFinder.findSingleMainClass(this.classesRoot, SPRING_BOOT_APPLICATION_CLASS_NAME);
7373
}
74-
return MainClassFinder.findSingleMainClass(new JarFile(this.classesRoot), "/",
75-
SPRING_BOOT_APPLICATION_CLASS_NAME);
74+
try (JarFile jarFile = new JarFile(this.classesRoot)) {
75+
return MainClassFinder.findSingleMainClass(jarFile, "/", SPRING_BOOT_APPLICATION_CLASS_NAME);
76+
}
7677
}
7778
catch (IOException ex) {
7879
throw new BuildException(ex);

0 commit comments

Comments
 (0)