File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
main/java/org/springframework/core/io
test/java/org/springframework/core/io/support Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,16 @@ else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
8686 if (con instanceof JarURLConnection jarCon ) {
8787 // For JarURLConnection, do not check content-length but rather the
8888 // existence of the entry (or the jar root in case of no entryName).
89- return (jarCon .getEntryName () == null || jarCon .getJarEntry () != null );
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 ();
98+ }
9099 }
91100 else if (con .getContentLengthLong () > 0 ) {
92101 return true ;
Original file line number Diff line number Diff line change @@ -335,6 +335,11 @@ private void writeAssetJar(Path path) throws Exception {
335335 }
336336 assertThat (new FileSystemResource (path ).exists ()).isTrue ();
337337 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
338+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" ).exists ()).isTrue ();
339+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/none.txt" ).exists ()).isFalse ();
340+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isFalse ();
341+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" ).exists ()).isFalse ();
342+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/none.txt" ).exists ()).isFalse ();
338343 }
339344
340345 private void writeApplicationJar (Path path ) throws Exception {
You can’t perform that action at this time.
0 commit comments