Open ppkarwasz opened 8 months ago
There are more (platform-independent!) hazards surrounding FileOutputStream::new
. Please indeed replace them with Files::newOutputStream
.
I like this idea because it also supports use of other file system implementations based on what the user has installed. That could also be useful in tests if we used something like https://github.com/google/jimfs for in-memory file system testing.
Since Java 7 two methods are available to open new files:
FileOutputStream#new
,Files#newOutputStream
.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 theFILE_SHARE_DELETE
option (cf. this SO question).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.