Resource.lastModified() propagates 0 value if target resource exists

Issue: SPR-17320
This commit is contained in:
Juergen Hoeller
2018-10-10 00:31:49 +02:00
parent 547b841172
commit b53995b5d4

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -55,8 +55,7 @@ public abstract class AbstractResource implements Resource {
catch (IOException ex) { catch (IOException ex) {
// Fall back to stream existence: can we open the stream? // Fall back to stream existence: can we open the stream?
try { try {
InputStream is = getInputStream(); getInputStream().close();
is.close();
return true; return true;
} }
catch (Throwable isEx) { catch (Throwable isEx) {
@@ -126,7 +125,7 @@ public abstract class AbstractResource implements Resource {
Assert.state(is != null, "Resource InputStream must not be null"); Assert.state(is != null, "Resource InputStream must not be null");
try { try {
long size = 0; long size = 0;
byte[] buf = new byte[255]; byte[] buf = new byte[256];
int read; int read;
while ((read = is.read(buf)) != -1) { while ((read = is.read(buf)) != -1) {
size += read; size += read;
@@ -149,10 +148,11 @@ public abstract class AbstractResource implements Resource {
*/ */
@Override @Override
public long lastModified() throws IOException { public long lastModified() throws IOException {
long lastModified = getFileForLastModifiedCheck().lastModified(); File fileToCheck = getFileForLastModifiedCheck();
if (lastModified == 0L) { long lastModified = fileToCheck.lastModified();
if (lastModified == 0L && !fileToCheck.exists()) {
throw new FileNotFoundException(getDescription() + throw new FileNotFoundException(getDescription() +
" cannot be resolved in the file system for resolving its last-modified timestamp"); " cannot be resolved in the file system for checking its last-modified timestamp");
} }
return lastModified; return lastModified;
} }