JDK-8254876 : (fs) NullPointerException not thrown when first argument to Path.of or Paths.get is null
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 8,11,15,16
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2020-10-15
  • Updated: 2021-01-14
  • Resolved: 2020-11-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b23Fixed
Related Reports
CSR :  
Relates :  
Sub Tasks
JDK-8260872 :  
Description
A DESCRIPTION OF THE PROBLEM :
First argument of java.nio.file.Paths.get(String first, String... more) method allows null parameter and transforms it to "null" string.

Example code:

java.nio.file.Path path = java.nio.file.Paths.get(null, "a");
System.out.println(path);
System.out.println(path.toAbsolutePath());

Output:
null\a
c:\Program Files\Java\jdk-15\bin\null\a

Looks like a bug for me.
Also JavaDoc for java.nio.file package state "Unless otherwise noted, passing a null argument to a constructor or method of any class or interface in this package will cause a NullPointerException to be thrown.".


FREQUENCY : always
Comments
I checked my test case with JDK-16 and yes, the bug is fixed. Now NPE is thrown, as expected.
14-01-2021

Requested the submitter verify the fix with latest version of JDK 16.
13-01-2021

Changeset: 450452bb Author: Brian Burkhalter <bpb@openjdk.org> Date: 2020-11-03 19:39:28 +0000 URL: https://github.com/openjdk/jdk/commit/450452bb
03-11-2020

This appears to be an oversight that goes back to JDK 7. The implementation of getPath in both UnixFileSystem and WindowsFileSystem do not check if "first" is null when called with two or more arguments.
16-10-2020

The observations on Windows 10: JDK 8: Failed because NullPointerException was not thrown JDK 11: Failed JDK 15: Failed JDK 16: Failed
16-10-2020