Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileUrlResource isWritable method returns true if URL protocol is not indicating a file #25584

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -59,6 +59,7 @@ public class FileUrlResource extends UrlResource implements WritableResource {
*/
public FileUrlResource(URL url) {
super(url);
Assert.isTrue(ResourceUtils.isFileURL(url),"url's protocol must be file or start with vfs");
}

/**
Expand Down Expand Up @@ -96,7 +97,7 @@ public boolean isWritable() {
return (file.canWrite() && !file.isDirectory());
}
else {
return true;
return false;
}
}
catch (IOException ex) {
Expand Down
Expand Up @@ -330,4 +330,11 @@ void readableChannelNotFoundOnClassPathResource() throws IOException {
new ClassPathResource("Resource.class", getClass()).createRelative("X").readableChannel());
}

@Test
void fileUrlResourceTest() throws IOException {
assertThatIllegalArgumentException().isThrownBy(() -> {
new FileUrlResource(new URL("https://spring.io/"));
});
}

}