File tree 2 files changed +12
-12
lines changed
spring-core/src/main/java/org/springframework/core/io 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ else if (code == HttpURLConnection.HTTP_NOT_FOUND) {
80
80
}
81
81
}
82
82
}
83
- catch (Exception ex ) {
83
+ catch (IOException ex ) {
84
84
return false ;
85
85
}
86
86
}
@@ -110,18 +110,18 @@ public boolean isReadable() {
110
110
if (contentLength > 0 ) {
111
111
return true ;
112
112
}
113
- else if (contentLength < 0 ) {
113
+ else if (contentLength == 0 ) {
114
+ // Empty file or directory -> not considered readable...
114
115
return false ;
115
116
}
116
- // 0 length: either an empty file or a directory...
117
- // On current JDKs, this will trigger an NPE from within the close() call
118
- // for directories, only returning true for actual files with 0 length.
119
- getInputStream (). close () ;
120
- return true ;
117
+ else {
118
+ // Fall back to stream existence: can we open the stream?
119
+ getInputStream (). close ();
120
+ return true ;
121
+ }
121
122
}
122
123
}
123
- catch (Exception ex ) {
124
- // Usually an IOException but potentially a NullPointerException (see above)
124
+ catch (IOException ex ) {
125
125
return false ;
126
126
}
127
127
}
@@ -135,7 +135,7 @@ public boolean isFile() {
135
135
}
136
136
return ResourceUtils .URL_PROTOCOL_FILE .equals (url .getProtocol ());
137
137
}
138
- catch (Exception ex ) {
138
+ catch (IOException ex ) {
139
139
return false ;
140
140
}
141
141
}
@@ -186,7 +186,7 @@ protected boolean isFile(URI uri) {
186
186
}
187
187
return ResourceUtils .URL_PROTOCOL_FILE .equals (uri .getScheme ());
188
188
}
189
- catch (Exception ex ) {
189
+ catch (IOException ex ) {
190
190
return false ;
191
191
}
192
192
}
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ public interface Resource extends InputStreamSource {
60
60
boolean exists ();
61
61
62
62
/**
63
- * Indicate whether the contents of this resource can be read via
63
+ * Indicate whether non-empty contents of this resource can be read via
64
64
* {@link #getInputStream()}.
65
65
* <p>Will be {@code true} for typical resource descriptors that exist
66
66
* since it strictly implies {@link #exists()} semantics as of 5.1.
You can’t perform that action at this time.
0 commit comments