Summary
Change java.io.File.delete
so that it no longer deletes read-only regular files. Add a system property to restore prior behavior when true
.
Problem
The method java.io.File.delete
removes read-only regular files on Windows by first clearing the attributes and then deleting the file. This presents two problems. Firstly, if the file is marked read-only, then it should not be deleted. Secondly, if clearing the attribute succeeds but the deletion fails, then the file will still exist but in a modified state. Directories do not support the read-only attribute so for them this is not an issue.
Solution
Change the implementation of java.io.File.delete
on Windows to simply return false
for read-only files and neither modify the attributes nor attempt to delete the file. This change will affect java.io.File.deleteOnExit
as well since this method invokes File.delete
. There is no behavioral change for directories.
A system property jdk.io.File.allowDeleteReadOnlyFiles
is added such that if true
, the long standing behavior of removing the read-only attribute before deleting the file is reinstated.
Specification
There is no change to the specification.
- csr of
-
JDK-8355954 File.delete removes read-only files (win)
-
- In Progress
-