RFR: 8349812: (fs) Files.newByteChannel with empty path name and CREATE_NEW throws unexpected exception [v2]

Alan Bateman alanb at openjdk.org
Wed Feb 12 09:27:10 UTC 2025


On Wed, 12 Feb 2025 08:43:47 GMT, Maxim Kartashev <mkartashev at openjdk.org> wrote:

>> `UnixFileChannelFactory.open()` checks for the current directory by looking at the first byte of the name, which in case of an empty path is simply not there. This check throws an `ArrayIndexOutOfBoundsException` and prevents the correct exception from being thrown.
>> 
>> The suggested solution is to use another method that translates a path name into a byte array called `getByteArrayForSysCalls()` that is specifically designed to handle the case of empty path names.
>> 
>> Tested by running `java/nio` tests on Linux.
>
> Maxim Kartashev has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Updated the copyright year and added the bugid to the test

test/jdk/java/nio/file/Files/SBC.java line 433:

> 431:             Files.newByteChannel(Path.of(""), opts);
> 432:             throw new RuntimeException("FileAlreadyExistsException expected");
> 433:         } catch (FileAlreadyExistsException x) { }

While WRITE + CREATE_NEW are the options to tickle the bug, I think emptyPathTest should be expanded to test over combinations of open options. There are several code paths with options such as O_NOFOLLOW and DELETE_ON_CLOSE that will also need to be tested.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23560#discussion_r1952274932


More information about the nio-dev mailing list