RFR: 8349812: (fs) Files.newByteChannel with empty path name and CREATE_NEW throws unexpected exception
Alan Bateman
alanb at openjdk.org
Tue Feb 11 20:52:10 UTC 2025
On Tue, 11 Feb 2025 19:32:07 GMT, Brian Burkhalter <bpb 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.
>
> src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java line 198:
>
>> 196: // create flags
>> 197: if (flags.createNew) {
>> 198: byte[] pathForSysCall = path.getByteArrayForSysCalls();
>
> Does this need to be done at line 240 as well?
>
> fd = openat(dfd, path.asByteArray(), oflags, mode);
When *at functions the second parameter is relative to the open directory so need to be careful, need to make sure there are good tests before changing anything.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23560#discussion_r1951582355
More information about the nio-dev
mailing list