Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8356196

File.delete removes read-only files (win)

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • core-libs
    • None
    • behavioral
    • minimal
    • Some files that are expected to be deleted will not be.
    • Java API
    • SE

      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.

            bpb Brian Burkhalter
            bpb Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: