File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
spring-core/src/main/java/org/springframework/core/io Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 2929import java .nio .file .NoSuchFileException ;
3030import java .nio .file .StandardOpenOption ;
3131import java .util .jar .JarEntry ;
32+ import java .util .jar .JarFile ;
3233
3334import org .springframework .util .ResourceUtils ;
3435
4445 */
4546public 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 ) {
You can’t perform that action at this time.
0 commit comments