Skip to content

Commit b53995b

Browse files
committed
Resource.lastModified() propagates 0 value if target resource exists
Issue: SPR-17320
1 parent 547b841 commit b53995b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

spring-core/src/main/java/org/springframework/core/io/AbstractResource.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,8 +55,7 @@ public boolean exists() {
5555
catch (IOException ex) {
5656
// Fall back to stream existence: can we open the stream?
5757
try {
58-
InputStream is = getInputStream();
59-
is.close();
58+
getInputStream().close();
6059
return true;
6160
}
6261
catch (Throwable isEx) {
@@ -126,7 +125,7 @@ public long contentLength() throws IOException {
126125
Assert.state(is != null, "Resource InputStream must not be null");
127126
try {
128127
long size = 0;
129-
byte[] buf = new byte[255];
128+
byte[] buf = new byte[256];
130129
int read;
131130
while ((read = is.read(buf)) != -1) {
132131
size += read;
@@ -149,10 +148,11 @@ public long contentLength() throws IOException {
149148
*/
150149
@Override
151150
public long lastModified() throws IOException {
152-
long lastModified = getFileForLastModifiedCheck().lastModified();
153-
if (lastModified == 0L) {
151+
File fileToCheck = getFileForLastModifiedCheck();
152+
long lastModified = fileToCheck.lastModified();
153+
if (lastModified == 0L && !fileToCheck.exists()) {
154154
throw new FileNotFoundException(getDescription() +
155-
" cannot be resolved in the file system for resolving its last-modified timestamp");
155+
" cannot be resolved in the file system for checking its last-modified timestamp");
156156
}
157157
return lastModified;
158158
}

0 commit comments

Comments
 (0)