JDK-8263940 : NPE when creating default file system when default file system provider is packaged as JAR file on class path
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 9,17
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2021-03-22
  • Updated: 2024-04-29
  • Resolved: 2021-08-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 18
11.0.24-oracleFixed 17.0.12-oracleFixed 18 b11Fixed
Related Reports
Relates :  
Description
If the system property java.nio.file.spi.DefaultFileSystemProvider is set to the name of a class in a JAR file on the class path then it leads to an NPE in the ZipFile code. This is a bootstrapping/initialization issue (and a regression since JDK 9) due to the ZipFile code needing to use the default file system provider. We may have to change ZipFile to use the built-in file system provider, at least for the class path case.


$ java -cp classes:provider.jar -Djava.nio.file.spi.DefaultFileSystemProvider=TestProvider org.test.Test

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)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:100)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:94)
	at java.base/java.nio.file.FileSystems.getDefault(FileSystems.java:182)
	at org.test.Test.main(Test.java:7)
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:2318)
	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1246)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:707)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:241)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:172)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:349)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.getJarFile(URLClassPath.java:816)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader$1.run(URLClassPath.java:761)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader$1.run(URLClassPath.java:754)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:753)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.<init>(URLClassPath.java:728)
	at java.base/jdk.internal.loader.URLClassPath$3.run(URLClassPath.java:496)
	at java.base/jdk.internal.loader.URLClassPath$3.run(URLClassPath.java:479)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
	at java.base/jdk.internal.loader.URLClassPath.getLoader(URLClassPath.java:478)
	at java.base/jdk.internal.loader.URLClassPath.getLoader(URLClassPath.java:447)
	at java.base/jdk.internal.loader.URLClassPath.getResource(URLClassPath.java:316)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:750)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:466)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:123)
	... 7 more
Comments
[jdk11u-fix-request] Approval Request from Amos "Backporting for parity with 11.0.24-oracle. Un-Clean backport. SAP nightlies passed on 2024-04-16,17,19,20”
23-04-2024

[jdk17u-fix-request] Approval Request from Amos "Backporting for parity with 17.0.12-oracle. Un-Clean backport. SAP nightlies passed on 2024-04-17,19,20”
21-04-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/2647 Date: 2024-04-11 06:57:36 +0000
11-04-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/2390 Date: 2024-04-11 06:02:58 +0000
11-04-2024

Changeset: 717792c3 Author: Lance Andersen <lancea@openjdk.org> Date: 2021-08-13 16:11:04 +0000 URL: https://git.openjdk.java.net/jdk/commit/717792c3b728584413572e7aede83290779be2a2
13-08-2021

The testFileSystemProvider.zip includes a test case which can be run via sh runnit.sh.
26-03-2021

The attached test case can be run after unzipping testfsp.zip via: java -cp .:test.jar -Djava.nio.file.spi.DefaultFileSystemProvider=TestProvider
22-03-2021

test/jdk/java/nio/file/spi/SetDefaultProvider.java tests overriding the default file system provider where the provider is exploded on the class path, deployed as an exploded module, as a modular JAR and where it patched combinations. The issue slipped through because the test doesn't exercise the case where the provider is in a JAR file on the class path.
22-03-2021