Replacing default FileSystemProvider

Michael Hall mik3hall at gmail.com
Fri Mar 19 20:11:45 UTC 2021


This may not be the correct forum to ask about this. If I should try posting to StackOverflow or elsewhere that’s fine if you indicate that.

I wrote a Mac specific FileSystemProvider sometime back that replaced the default, prior to Java 9 modular.I get exceptions shortened to ones that follow at the end.  I shortened that to as simple a test case as possible.

public class Test {
	
	public static void main(String [] args) {
		System.out.println(FileSystems.getDefault());
	}
	
}

class TestProvider extends FileSystemProvider {
    private final FileSystemProvider priorProvider;
    private static final String scheme = "file”;

…

}

Which gets the same exceptions. I’ve noticed there were similar issues with getDefault() returning null about the time of Java 9 modular.
Are any of these issues still open? Is there anything different that should be done now? Is there any documentation I should look at?

The exceptions…

java -cp test.jar -Djava.nio.file.spi.DefaultFileSystemProvider=org.test.TestProvider -d . Test.java
Exception in thread "main" java.lang.Error: java.lang.NullPointerException: Cannot invoke "java.nio.file.FileSystem.getPath(String, String[])" because the return value of "java.nio.file.FileSystems.getDefault()" is null
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:133)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:102)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:100)

Both the old code and the simpler test case seem to get these in pairs.

Caused by: java.lang.NullPointerException: Cannot invoke "java.nio.file.FileSystem.getPath(String, String[])" because the return value of "java.nio.file.FileSystems.getDefault()" is null
	at java.base/java.io.File.toPath(File.java:2316)


More information about the nio-dev mailing list