Skip to content

Commit 014a395

Browse files
committed
Merge branch '6.2.x'
2 parents ffb32f4 + 253f321 commit 014a395

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Diff for: spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.nio.file.NoSuchFileException;
3030
import java.nio.file.StandardOpenOption;
3131
import java.util.jar.JarEntry;
32+
import java.util.jar.JarFile;
3233

3334
import org.springframework.util.ResourceUtils;
3435

@@ -44,6 +45,7 @@
4445
*/
4546
public abstract class AbstractFileResolvingResource extends AbstractResource {
4647

48+
@SuppressWarnings("try")
4749
@Override
4850
public boolean exists() {
4951
try {
@@ -86,15 +88,10 @@ else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
8688
if (con instanceof JarURLConnection jarCon) {
8789
// For JarURLConnection, do not check content-length but rather the
8890
// existence of the entry (or the jar root in case of no entryName).
89-
try {
90-
if (jarCon.getEntryName() == null) {
91-
// Jar root: check for the existence of any actual jar entries.
92-
return jarCon.getJarFile().entries().hasMoreElements();
93-
}
94-
return (jarCon.getJarEntry() != null);
95-
}
96-
finally {
97-
jarCon.getJarFile().close();
91+
// getJarFile() called for enforced presence check of the jar file,
92+
// throwing a NoSuchFileException otherwise (turned to false below).
93+
try (JarFile jarFile = jarCon.getJarFile()) {
94+
return (jarCon.getEntryName() == null || jarCon.getJarEntry() != null);
9895
}
9996
}
10097
else if (con.getContentLengthLong() > 0) {

0 commit comments

Comments
 (0)