apache / apache/logging-log4j2

Consider replacing `FileOutputStream` with `Files.newOutputStream`

Open
#2,117 4 comments 0 reactions 0 assignees View on GitHub
appenders enhancement runtime
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

Since Java 7 two methods are available to open new files:

- [`FileOutputStream#new`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/FileOutputStream.html),
- [`Files#newOutputStream`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#newOutputStream(java.nio.file.Path,java.nio.file.OpenOption...)).

While they mostly perform the same OS operations, there is a significant difference between the two on Windows: the IO method opens the file **without** the `FILE_SHARE_DELETE` option, whereas the NIO method adds the `FILE_SHARE_DELETE` option (cf. [this SO question](https://stackoverflow.com/q/63584311/11748454)).

Since log files on UNIX can already be deleted without stopping the application, this change would allow an alignment between the behavior of Log4j on Windows and UNIX.

I discussed this with @garydgregory on Slack.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.