RFR: 8254876: (fs) NullPointerException not thrown when first argument to Path.of or Paths.get is null
Brian Burkhalter
bpb at openjdk.java.net
Mon Nov 2 21:59:56 UTC 2020
On Mon, 2 Nov 2020 21:54:50 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Please review this simple fix to have Path.of(String,String) throw a NullPointerException if the first parameter is null.
>
> src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java line 264:
>
>> 262: path = first;
>> 263: } else {
>> 264: if (first == null) {
>
> `Objects.requireNonNull(first)` does this in fewer lines and a bit more explicitly.
>
> Should it be checking `first` always, not just in the case `more.length != 0`?
> (It will throw NPE, but not until `UnixPath.normalizeAndCheck(path))`.
Good point on the Objects call. I checked the more.length == 0 case and let if fall through to the UnixPath method. It might be more straightforward to always check however.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1020
More information about the nio-dev
mailing list