FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux xxx 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u1 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
java.lang.NullPointerException
at sun.nio.fs.UnixPath.normalizeAndCheck(UnixPath.java:77)
at sun.nio.fs.UnixPath.(UnixPath.java:71)
at sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:281)
at java.nio.file.Paths.get(Paths.java:84)
when using Path p = Paths.get(null);
There is no javadoc indicating the NullPointerException, and according to the javadoc it should throw "InvalidPathException - if the path string cannot be converted to a Path"
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just use Paths.get(null); on an unix system (which will use UnixPath)
I just tested other things on windows :
Paths.get(null) leads to :
Exception in thread "main" java.lang.NullPointerException
at java.nio.file.Paths.get(Paths.java:132)
at atest.test.main(test.java:15)
and Paths.get((String)null); leads to :
Exception in thread "main" java.lang.NullPointerException
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:98)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.nio.file.Paths.get(Paths.java:84)
at atest.test.main(test.java:16)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect some javadocs comments or correct exceptions to be thrown (IllegalArgumentException ?)
ACTUAL -
Multiple different errors depending on the platform and the signature of Paths.get used.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(String[] args) {
try {
Paths.get(null);
} catch (Exception e) {
System.out.println("Path.get(URI) with null arg error");
e.printStackTrace();
}
try {
Paths.get((String) null);
} catch (Exception e) {
System.out.println("Path.get(String...varargs) with null arg error");
e.printStackTrace();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Null check before using Paths.get() with "if"
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux xxx 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u1 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
java.lang.NullPointerException
at sun.nio.fs.UnixPath.normalizeAndCheck(UnixPath.java:77)
at sun.nio.fs.UnixPath.(UnixPath.java:71)
at sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:281)
at java.nio.file.Paths.get(Paths.java:84)
when using Path p = Paths.get(null);
There is no javadoc indicating the NullPointerException, and according to the javadoc it should throw "InvalidPathException - if the path string cannot be converted to a Path"
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just use Paths.get(null); on an unix system (which will use UnixPath)
I just tested other things on windows :
Paths.get(null) leads to :
Exception in thread "main" java.lang.NullPointerException
at java.nio.file.Paths.get(Paths.java:132)
at atest.test.main(test.java:15)
and Paths.get((String)null); leads to :
Exception in thread "main" java.lang.NullPointerException
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:98)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.nio.file.Paths.get(Paths.java:84)
at atest.test.main(test.java:16)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect some javadocs comments or correct exceptions to be thrown (IllegalArgumentException ?)
ACTUAL -
Multiple different errors depending on the platform and the signature of Paths.get used.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(String[] args) {
try {
Paths.get(null);
} catch (Exception e) {
System.out.println("Path.get(URI) with null arg error");
e.printStackTrace();
}
try {
Paths.get((String) null);
} catch (Exception e) {
System.out.println("Path.get(String...varargs) with null arg error");
e.printStackTrace();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Null check before using Paths.get() with "if"