RFO: open RandomAccessFile with FILE_SHARE_DELETE on Windows

Jaikiran Pai jaikiran.pai at oracle.com
Thu Dec 25 07:17:46 UTC 2025


Hello Maxim,

Some years back, there were some experiments that were done for the 
usage of FILE_SHARE_DELETE on Windows, for 
https://bugs.openjdk.org/browse/JDK-8224794. The related mailing list 
thread here 
https://mail.openjdk.org/pipermail/core-libs-dev/2021-November/083809.html 
has additional details why it was decided not to use that option (even 
though that mail talks about ZipFile/JarFile, the underlying code uses 
RandomAccessFile).

-Jaikiran

On 25/12/25 12:34 pm, Maxim Kartashev wrote:
> Hi All,
>
> Currently, the following snippet will not succeed on Windows
> try (RandomAccessFile ignored = new RandomAccessFile(f, "r")) {
>     f.delete();
> }
> because RandomAccessFile is opened without the FILE_SHARE_DELETE 
> option for the CreateFileW() call.
> I wonder if this is intentional and what, if anything, would break if 
> this decision is reversed and FILE_SHARE_DELETE is supplied? I suspect 
> applications rely on the existing semantics but can't give concrete 
> examples myself.
>
> Appreciate your input.
>
> Maxim.


More information about the nio-dev mailing list