RFR: 8073061: (fs) Files.copy(foo, bar, REPLACE_EXISTING) deletes bar even if foo is not readable [v5]

Brian Burkhalter bpb at openjdk.org
Fri Sep 15 16:54:38 UTC 2023


On Fri, 15 Sep 2023 16:40:05 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> This change looks reasonable, but it causes `CopyAndMove` to fail at line 777 in
>> 
>> * Test: copy regular file, target exists
>> 
>> due to an exception in `Files.copy`:
>> 
>> try (InputStream in = Files.newInputStream(source)) {
>>     Files.copy(in, target, opts.replaceExistingOrEmpty());
>> }
>> 
>> The new method `replaceExistingOrEmpty` returns a zero-length array as `copyAttributes` is `false`.
>
> There may be a typo, it should be an empty array when replaceExisting (not copyAttributes) is false. The main point is that copy from an input stream to a file already supports REPLACE_EXISTING option.

Looks like it was a typo. All `java/nio/file/Files` tests pass with this version.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15501#discussion_r1327560362


More information about the nio-dev mailing list