Commit c08c2a3 1 parent 2bb061c commit c08c2a3 Copy full SHA for c08c2a3
File tree 2 files changed +28
-0
lines changed
src/java.base/share/classes/java/lang
test/jdk/java/nio/file/spi
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 53
53
import java .security .AccessController ;
54
54
import java .security .CodeSource ;
55
55
import java .security .PrivilegedAction ;
56
+ import java .nio .file .FileSystems ;
56
57
import java .security .ProtectionDomain ;
57
58
import java .util .Collections ;
58
59
import java .util .List ;
@@ -2335,6 +2336,16 @@ private static void initPhase3() {
2335
2336
// set TCCL
2336
2337
Thread .currentThread ().setContextClassLoader (scl );
2337
2338
2339
+ if (Boolean .getBoolean ("java.util.zip.use.nio.for.zip.file.access" )
2340
+ && System .getProperty ("java.nio.file.spi.DefaultFileSystemProvider" ) != null ) {
2341
+ // Make sure the custom file system(s) are loaded using the "standard" ZipFile operating mode
2342
+ // rather than the one that forwards to NIO. The latter will use the file system that is being loaded to
2343
+ // try to load files, which will result in an NPE from FileSystems.getDefault().
2344
+ // Calling FileSystems.getDefault() here bypasses that because the NIO operating mode of ZipFile only
2345
+ // activates at init level 4.
2346
+ FileSystems .getDefault ();
2347
+ }
2348
+
2338
2349
// system is fully initialized
2339
2350
VM .initLevel (4 );
2340
2351
}
Original file line number Diff line number Diff line change @@ -201,6 +201,23 @@ private String ofClasspath(String... paths) {
201
201
return String .join (File .pathSeparator , paths );
202
202
}
203
203
204
+ /**
205
+ * Test the file system provider located in a jar with
206
+ * -Djava.util.zip.use.nio.for.zip.file.access=true
207
+ * that makes ZipFile use NIO to read the jar.
208
+ */
209
+ public void testClassPathWithFileSystemProviderJarAndNioForZipFile () throws Exception {
210
+ String testClasses = System .getProperty ("test.classes" );
211
+ Path fspJar = Path .of ("testFileSystemProvider.jar" );
212
+ Files .deleteIfExists (fspJar );
213
+ createFileSystemProviderJar (fspJar , Path .of (testClasses ));
214
+ String jarFile = createModularJar ();
215
+ String classpath = ofClasspath (fspJar .toString (), jarFile , testClasses );
216
+ int exitValue = exec (SET_DEFAULT_FSP , "-Djava.util.zip.use.nio.for.zip.file.access=true" ,
217
+ "-cp" , classpath , "p.Main" );
218
+ assertEquals (exitValue , 0 );
219
+ }
220
+
204
221
/**
205
222
* Returns the directory containing the classes for the given module.
206
223
*/
You can’t perform that action at this time.
0 commit comments