Java8 FileSystems.getDefault() throws ExceptionInInitializerError 由 WindowsPathParser 中的 NullPointerException 引起
Java8 FileSystems.getDefault() throws ExceptionInInitializerError caused by NullPointerException in WindowsPathParser
对 Paths.get() 的简单调用会引发由 WindowsPathParser 中的 NullPointerException 引起的 ExceptionInInitializerError。我在 Windows7 Enterprise 上使用 Oracle jdk 1.8.0_131 64 位。
static Path outPath;
public static void main(String[] args) {
outPath = Paths.get("data");
}
异常堆栈跟踪
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at java.nio.file.Paths.get(Paths.java:84)
at com.xpo.or.agg.specific.Program.instantiate(Program.java:62)
at com.xpo.or.agg.specific.Program.main(Program.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: 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.WindowsFileSystem.<init>(WindowsFileSystem.java:57)
at sun.nio.fs.WindowsFileSystemProvider.<init>(WindowsFileSystemProvider.java:53)
at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:36)
at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
at java.nio.file.FileSystems$DefaultFileSystemHolder.access[=13=]0(FileSystems.java:89)
at java.nio.file.FileSystems$DefaultFileSystemHolder.run(FileSystems.java:98)
at java.nio.file.FileSystems$DefaultFileSystemHolder.run(FileSystems.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96)
at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
我唯一能想到的问题是静态成员程序 class 初始化和 java.nio.file.FileSystems 初始化之间的一些副作用。
java.lang.ExceptionInInitializerError 表示在静态初始化程序中发生了意外异常。
抛出 ExceptionInInitializerError
表示
评估静态初始值设定项或
静态变量的初始值设定项。
感谢任何帮助。
嗯...我认为问题是 user.dir
系统 属性 由于某种原因是 null
。原因是(我猜)在你的 IDE 配置中的某个地方。例如:
public static void main(String[] args) {
System.getProperties().remove("user.dir");
outPath = Paths.get("data");
}
将在不同环境中重现您的确切问题:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at java.nio.file.Paths.get(Paths.java:84)
我是 Eclipse/STS 用户,此 属性 来自应用程序的 运行 配置,但我不确定您如何(错误)配置它IntelliJ。无论如何 - 缺少 user.dir
是你的问题。
对 Paths.get() 的简单调用会引发由 WindowsPathParser 中的 NullPointerException 引起的 ExceptionInInitializerError。我在 Windows7 Enterprise 上使用 Oracle jdk 1.8.0_131 64 位。
static Path outPath;
public static void main(String[] args) {
outPath = Paths.get("data");
}
异常堆栈跟踪
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at java.nio.file.Paths.get(Paths.java:84)
at com.xpo.or.agg.specific.Program.instantiate(Program.java:62)
at com.xpo.or.agg.specific.Program.main(Program.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: 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.WindowsFileSystem.<init>(WindowsFileSystem.java:57)
at sun.nio.fs.WindowsFileSystemProvider.<init>(WindowsFileSystemProvider.java:53)
at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:36)
at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
at java.nio.file.FileSystems$DefaultFileSystemHolder.access[=13=]0(FileSystems.java:89)
at java.nio.file.FileSystems$DefaultFileSystemHolder.run(FileSystems.java:98)
at java.nio.file.FileSystems$DefaultFileSystemHolder.run(FileSystems.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:96)
at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
我唯一能想到的问题是静态成员程序 class 初始化和 java.nio.file.FileSystems 初始化之间的一些副作用。
java.lang.ExceptionInInitializerError 表示在静态初始化程序中发生了意外异常。
抛出 ExceptionInInitializerError
表示
评估静态初始值设定项或
静态变量的初始值设定项。
感谢任何帮助。
嗯...我认为问题是 user.dir
系统 属性 由于某种原因是 null
。原因是(我猜)在你的 IDE 配置中的某个地方。例如:
public static void main(String[] args) {
System.getProperties().remove("user.dir");
outPath = Paths.get("data");
}
将在不同环境中重现您的确切问题:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
at java.nio.file.Paths.get(Paths.java:84)
我是 Eclipse/STS 用户,此 属性 来自应用程序的 运行 配置,但我不确定您如何(错误)配置它IntelliJ。无论如何 - 缺少 user.dir
是你的问题。