RFR: 8355954: File.delete removes read-only files (win)

Alan Bateman alanb at openjdk.org
Thu May 1 12:43:45 UTC 2025


On Wed, 30 Apr 2025 23:38:02 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> This change proposes to modify `java.io.File.delete()` so that regular files on Windows will not be deleted by default if their read-only attribute is set. A boolean-valued system compatibility property `jdk.io.File.deleteReadOnly` is defined to reinstate legacy behavior if desired.

I've added the "csr" label as we will need to create a CSR for this. It will need a release note too.

src/java.base/windows/classes/java/io/WinNTFileSystem.java line 45:

> 43: 
> 44:     private static final boolean DELETE_READONLY =
> 45:         Boolean.getBoolean("jdk.io.File.deleteReadOnly");

What would you think of allowDeleteReadOnlyFiles rather than deleteReadOnly?

src/java.base/windows/native/libjava/WinNTFileSystem_md.c line 665:

> 663:         BOOL attrSet = FALSE;
> 664:         if (deleteReadOnly && ((a & FILE_ATTRIBUTE_READONLY) != 0))
> 665:             attrSet = SetFileAttributesW(path, a & (~FILE_ATTRIBUTE_READONLY));

A small comment on the name "attrSet". It hints that it will be set to TRUE if the attribute is set whereas the use here is to mean that SetFileAttributesW has succeeded, a bit confusing because it's clearing the READONLY value, not setting it.  If you rename to something that has the word "modified" or "cleared" might be easy for future maintainers.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/24977#issuecomment-2844767305
PR Review Comment: https://git.openjdk.org/jdk/pull/24977#discussion_r2070223272
PR Review Comment: https://git.openjdk.org/jdk/pull/24977#discussion_r2070222588


More information about the core-libs-dev mailing list