changeset 59209:0bd09f6d2617

8218268: Javac treats Manifest Class-Path entries as Paths instead of URLs Reviewed-by: mchung, bchristi
author jjg
date Fri, 06 Dec 2019 13:03:39 -0800
parents 3b9efbac1b50
children 01cb61a27e61
files src/jdk.compiler/share/classes/com/sun/tools/javac/file/FSInfo.java
diffstat 1 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/FSInfo.java	Fri Dec 06 12:13:25 2019 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/FSInfo.java	Fri Dec 06 13:03:39 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,9 @@
 
 import java.io.IOError;
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.InvalidPathException;
@@ -92,7 +95,6 @@
     }
 
     public List<Path> getJarClassPath(Path file) throws IOException {
-        Path parent = file.getParent();
         try (JarFile jarFile = new JarFile(file.toFile())) {
             Manifest man = jarFile.getManifest();
             if (man == null)
@@ -107,17 +109,18 @@
                 return Collections.emptyList();
 
             List<Path> list = new ArrayList<>();
+            URL base = file.toUri().toURL();
 
             for (StringTokenizer st = new StringTokenizer(path);
                  st.hasMoreTokens(); ) {
                 String elt = st.nextToken();
                 try {
-                    Path f = FileSystems.getDefault().getPath(elt);
-                    if (!f.isAbsolute() && parent != null)
-                        f = parent.resolve(f).toAbsolutePath();
-                    list.add(f);
-                } catch (InvalidPathException | IOError e) {
-                    throw new IOException(e);
+                    URL url = tryResolveFile(base, elt);
+                    if (url != null) {
+                        list.add(Path.of(url.toURI()));
+                    }
+                } catch (URISyntaxException ex) {
+                    throw new IOException(ex);
                 }
             }
 
@@ -125,6 +128,25 @@
         }
     }
 
+    /**
+     * Attempt to return a file URL by resolving input against a base file
+     * URL.
+     *
+     * @return the resolved URL or null if the input is an absolute URL with
+     *         a scheme other than file (ignoring case)
+     * @throws MalformedURLException
+     */
+    static URL tryResolveFile(URL base, String input) throws MalformedURLException {
+        URL retVal = new URL(base, input);
+        if (input.indexOf(':') >= 0 && !"file".equalsIgnoreCase(retVal.getProtocol())) {
+            // 'input' contains a ':', which might be a scheme, or might be
+            // a Windows drive letter.  If the resolved file has a protocol
+            // that isn't "file:", it should be ignored.
+            return null;
+        }
+        return retVal;
+    }
+
     private FileSystemProvider jarFSProvider;
 
     public synchronized FileSystemProvider getJarFSProvider() {