Summary
Modify implementation such that java.nio.file.Path.of(String first, String... more)
and java.nio.file.Paths.get(String first, String... more)
throw a NullPointerException
when first
is null
.
Problem
The package specification of java.nio.file
states that
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.
but the aforementioned methods do not throw a NullPointerException
. This is incorrect behavior not only due to failing to throw the exception, but more in terms of allowing a corrupted path name containing the string "null"
to be created. This could lead to unexpected and possibly confusing behavior.
Solution
Modify the implementations of getPath(String first, String... more)
in the UnixFileSystem
and WindowsFileSystem
classes in the internal sun.nio.fs
package such that they throw NullPointerException
if the first parameter first
is null
. Paths.get
calls Path.of()
which calls XFileSystem.getPath()
.
Specification
There is no change to the existing specification per se.
- csr of
-
JDK-8254876 (fs) NullPointerException not thrown when first argument to Path.of or Paths.get is null
-
- Closed
-