File tree 1 file changed +6
-9
lines changed
spring-core/src/main/java/org/springframework/core/io
1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 29
29
import java .nio .file .NoSuchFileException ;
30
30
import java .nio .file .StandardOpenOption ;
31
31
import java .util .jar .JarEntry ;
32
+ import java .util .jar .JarFile ;
32
33
33
34
import org .springframework .util .ResourceUtils ;
34
35
44
45
*/
45
46
public abstract class AbstractFileResolvingResource extends AbstractResource {
46
47
48
+ @ SuppressWarnings ("try" )
47
49
@ Override
48
50
public boolean exists () {
49
51
try {
@@ -86,15 +88,10 @@ else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
86
88
if (con instanceof JarURLConnection jarCon ) {
87
89
// For JarURLConnection, do not check content-length but rather the
88
90
// 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 );
98
95
}
99
96
}
100
97
else if (con .getContentLengthLong () > 0 ) {
You can’t perform that action at this time.
0 commit comments