-
Notifications
You must be signed in to change notification settings - Fork 149
Description
With Java 25, the behavior of File#delete()
has been changed for read-only files on Windows. Previously, the operation also removed read-only files whereas now the operation fails:
This also affects Eclipe's file system implementation, as LocalFile#delete()
will now fail for read-only files on Windows.
This can be seen when excuting the test case DeleteTest#testDeleteReadOnlyFile
with a JRE 25. This was found by executing the I-Build tests with Java 25 on Windows, thanks to @HannesWell who has set up an according Jenkins job. The results of that job show the exact same test failures as the job for Java 21, except for the mentioned test case:
https://ci.eclipse.org/releng/job/AutomatedTests/job/ep438I-unit-win32-x86_64-java25/3/testReport/
A potential solution is to simply make LocalFile#delete()
explicitly restore the preexisting behavior of also deleting read-only files by removing the read-only flag if necessary first. There already is specific code for handling the read-only case in LocalFile#delete()
which just became insufficent with the changed behavior in Java 25:
Lines 314 to 322 in 30180a8
} catch (AccessDeniedException e) { | |
// If the file is read only, it can't be deleted via Files.deleteIfExists() | |
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=500306 | |
if (target.delete()) { | |
infMonitor.worked(); | |
return Status.OK_STATUS; | |
} | |
throw e; | |
} |
A workaround, as documented by the JDK release notes, is to restore the old behavior for an application with the flag: -Djdk.io.File.allowDeleteReadOnlyFiles=true