changeset 10828:24b6436df632

Overriding the default file system provider fails with a modular image
author alanb
date Wed, 15 Oct 2014 19:28:59 +0100
parents 3995fd63f47b
children 3150fbd1dbde
files src/java.base/share/classes/jdk/internal/jimage/ImageFile.java src/java.base/share/classes/jdk/internal/jimage/ImageReader.java src/java.base/share/classes/sun/misc/JImageCache.java
diffstat 3 files changed, 31 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/jimage/ImageFile.java	Wed Oct 15 16:27:29 2014 +0100
+++ b/src/java.base/share/classes/jdk/internal/jimage/ImageFile.java	Wed Oct 15 19:28:59 2014 +0100
@@ -32,7 +32,6 @@
 import java.nio.ByteOrder;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -76,7 +75,7 @@
 
     private ImageFile(Path path) {
         this.root = path;
-        this.mdir = root.resolve(Paths.get("lib", "modules"));
+        this.mdir = root.resolve(path.getFileSystem().getPath("lib", "modules"));
     }
 
     public static ImageFile open(Path path) throws IOException {
--- a/src/java.base/share/classes/jdk/internal/jimage/ImageReader.java	Wed Oct 15 16:27:29 2014 +0100
+++ b/src/java.base/share/classes/jdk/internal/jimage/ImageReader.java	Wed Oct 15 19:28:59 2014 +0100
@@ -24,13 +24,16 @@
  */
 package jdk.internal.jimage;
 
-import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 import java.nio.ByteOrder;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.nio.file.attribute.FileTime;
+import java.nio.file.spi.FileSystemProvider;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -44,6 +47,23 @@
     static final UTF8String META_INF_STRING = new UTF8String("META-INF");
     static final UTF8String PKG_MAP_STRING = new UTF8String("META-INF/package-to-module.properties");
 
+    /**
+     * The reader must use the underlying system file system provider, even if
+     * the default provider is configured to something else. This is to avoid
+     * recursive initialization issues trying to load the configured provider
+     * with the system class loader.
+     */
+    static final FileSystem FILE_SYSTEM;
+    static {
+        String s = System.getProperty("java.nio.file.spi.DefaultFileSystemProvider");
+        if (s == null) {
+            FILE_SYSTEM = FileSystems.getDefault();
+        } else {
+            FileSystemProvider provider = sun.nio.fs.DefaultFileSystemProvider.create();
+            FILE_SYSTEM = provider.getFileSystem(URI.create("file:///"));
+        }
+    }
+
     // attributes of the .jimage file. jimage file does not contain
     // attributes for the individual resources (yet). We use attributes
     // of the jimage file itself (creation, modification, access times).
@@ -67,8 +87,8 @@
     @Override
     public synchronized void open() throws IOException {
         super.open();
-        imageFileAttrs = Files.readAttributes(
-                new File(imagePath).toPath(), BasicFileAttributes.class);
+        imageFileAttrs = Files.readAttributes(FILE_SYSTEM.getPath(imagePath),
+                                              BasicFileAttributes.class);
         packageMap = PackageModuleMap.readFrom(this);
     }
 
--- a/src/java.base/share/classes/sun/misc/JImageCache.java	Wed Oct 15 16:27:29 2014 +0100
+++ b/src/java.base/share/classes/sun/misc/JImageCache.java	Wed Oct 15 19:28:59 2014 +0100
@@ -59,11 +59,14 @@
             return jimage;
 
         // not in cache so need to open it
-        String s = url.toString();
-        if (!s.startsWith("jimage:"))
+        if (!url.getProtocol().equalsIgnoreCase("jimage"))
             throw new IOException("not a jimage URL");
-        s = "file" + s.substring(6);
-        jimage = new ImageReader(URI.create(s).getPath());
+
+        // URL -> file path String
+        String path = url.getFile().replace('/', File.separatorChar);
+        path = new File(sun.net.www.ParseUtil.decode(path)).getPath();
+
+        jimage = new ImageReader(path);
         jimage.open();
 
         // potential race with other threads opening the same URL