Merge branch '7.0.x'

This commit is contained in:
Juergen Hoeller
2026-04-02 14:31:56 +02:00
2 changed files with 45 additions and 1 deletions
@@ -179,7 +179,7 @@ public class FileSystemResource extends AbstractResource implements WritableReso
*/
@Override
public boolean isReadable() {
return (this.file != null ? this.file.canRead() && !this.file.isDirectory() :
return (this.file != null ? this.file.exists() && this.file.canRead() && !this.file.isDirectory() :
Files.isReadable(this.filePath) && !Files.isDirectory(this.filePath));
}
@@ -270,6 +270,50 @@ class ResourceTests {
assertThat(relative).isEqualTo(new FileSystemResource("dir/subdir"));
}
@Test
void isReadableChecksExistsFirst() {
AtomicBoolean existsCalled = new AtomicBoolean();
AtomicBoolean canReadCalled = new AtomicBoolean();
File file = new File("/dev/my.txt") {
@Override
public boolean exists() {
existsCalled.set(true);
return false;
}
@Override
public boolean canRead() {
canReadCalled.set(true);
return false;
}
};
Resource resource = new FileSystemResource(file);
assertThat(resource.isReadable()).isFalse();
assertThat(existsCalled).isTrue();
assertThat(canReadCalled).isFalse();
}
@Test
void isReadableChecksCanReadAfterExists() {
AtomicBoolean existsCalled = new AtomicBoolean();
AtomicBoolean canReadCalled = new AtomicBoolean();
File file = new File("/dev/my.txt") {
@Override
public boolean exists() {
existsCalled.set(true);
return true;
}
@Override
public boolean canRead() {
canReadCalled.set(true);
return false;
}
};
Resource resource = new FileSystemResource(file);
assertThat(resource.isReadable()).isFalse();
assertThat(existsCalled).isTrue();
assertThat(canReadCalled).isTrue();
}
@Test
void getFilePath() throws Exception {
Path path = mock();