-
Bug
-
Resolution: Fixed
-
P3
-
9
-
b64
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8084862 | emb-9 | Brian Burkhalter | P3 | Resolved | Fixed | team |
j.n.f.Files.newBufferedWriter(Path, OpenOption...) throws SecurityException in case of StandardOpenOption.DELETE_ON_CLOSE usage. It seems like checkDelete is invoked and method throws an exception when delete is denied.
The same situation is observed in case of j.n.f.Files.newBufferedWriter(Path, Charset, OpenOption...).
Example:
Files.newBufferedWriter(myFilePath, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE);
We think that it will be good to add information about calling checkDelete by SecurityManager. Although it will looks strange because newBufferedWriter's spec doesn't contain information about optional ability of deleting files.
Tested with JDK9b37.
Failed JCK test is under development.
Code sample:
Path name = Paths.get("testfile");
System.setSecurityManager(new SecurityManager(){
@Override
public void checkWrite(FileDescriptor fd) {
// don't restrict anything
}
@Override
public void checkDelete(String file) {
if(file.equals(name.toString())){
throw new SecurityException("Couldn't delete file");
}
super.checkDelete(file);
}
});
try(BufferedWriter writer = Files.newBufferedWriter(name, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE)){
writer.write("test");
}
The same situation is observed in case of j.n.f.Files.newBufferedWriter(Path, Charset, OpenOption...).
Example:
Files.newBufferedWriter(myFilePath, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE);
We think that it will be good to add information about calling checkDelete by SecurityManager. Although it will looks strange because newBufferedWriter's spec doesn't contain information about optional ability of deleting files.
Tested with JDK9b37.
Failed JCK test is under development.
Code sample:
Path name = Paths.get("testfile");
System.setSecurityManager(new SecurityManager(){
@Override
public void checkWrite(FileDescriptor fd) {
// don't restrict anything
}
@Override
public void checkDelete(String file) {
if(file.equals(name.toString())){
throw new SecurityException("Couldn't delete file");
}
super.checkDelete(file);
}
});
try(BufferedWriter writer = Files.newBufferedWriter(name, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE)){
writer.write("test");
}
- backported by
-
JDK-8084862 (fs spec) Files.newBufferedWriter doesn't specify SecurityException for DELETE_ON_CLOSE option
-
- Resolved
-