RFR: 8349812: (fs) Files.newByteChannel with empty path name and CREATE_NEW throws unexpected exception
Brian Burkhalter
bpb at openjdk.org
Tue Feb 11 19:35:12 UTC 2025
On Tue, 11 Feb 2025 10:28:58 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.
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);
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23560#discussion_r1951477287
More information about the nio-dev
mailing list