smile-on
smile-on

Reputation: 2183

Java8 FileSystems.getDefault() throws ExceptionInInitializerError caused by NullPointerException in WindowsPathParser

A simple call to Paths.get() throws ExceptionInInitializerError caused by NullPointerException in WindowsPathParser. I am using Oracle jdk 1.8.0_131 64 bit on Windows7 Enterprise.

static Path outPath;

public static void main(String[] args) {
    outPath = Paths.get("data");
}

Exception stack trace

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$000(FileSystems.java:89)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98)
at java.nio.file.FileSystems$DefaultFileSystemHolder$1.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)

The only problem I can think of is some side effect between static member Program class initialization and java.nio.file.FileSystems initialization.

java.lang.ExceptionInInitializerError signals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.

Any help is appreciated.

Upvotes: 2

Views: 2489

Answers (1)

Lachezar Balev
Lachezar Balev

Reputation: 12031

Uhm... I believe that the problem is that the user.dir system property is null for some reason. And the reason is (I guess) somewhere in your IDE configuration. For example:

public static void main(String[] args) {
    System.getProperties().remove("user.dir");
    outPath = Paths.get("data");
}

will reproduce your exact problem across different environments:

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)

I'm an Eclipse/STS user and this property comes from the run configuration of the app, but I'm not sure how you may (mis)configure that in IntelliJ. Anyways - a missing user.dir is your problem.

Upvotes: 2

Related Questions