File tree 2 files changed +15
-1
lines changed
main/java/org/springframework/core/io
test/java/org/springframework/core/io/support
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) {
86
86
if (con instanceof JarURLConnection jarCon ) {
87
87
// For JarURLConnection, do not check content-length but rather the
88
88
// 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
+ }
90
99
}
91
100
else if (con .getContentLengthLong () > 0 ) {
92
101
return true ;
Original file line number Diff line number Diff line change @@ -335,6 +335,11 @@ private void writeAssetJar(Path path) throws Exception {
335
335
}
336
336
assertThat (new FileSystemResource (path ).exists ()).isTrue ();
337
337
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 ();
338
343
}
339
344
340
345
private void writeApplicationJar (Path path ) throws Exception {
You can’t perform that action at this time.
0 commit comments