8235361: JAR Class-Path no longer accepts relative URLs encoding absolute Windows paths (e.g "/C:/...")
Reviewed-by: alanb, mchung
This commit is contained in:
parent
eec0e71c04
commit
4627488e74
@ -1125,27 +1125,21 @@ public class URLClassPath {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to return a file URL by resolving input against a base file
|
* Attempt to return a file URL by resolving input against a base file
|
||||||
* URL. The input is an absolute or relative file URL that encodes a
|
* URL.
|
||||||
* file path.
|
|
||||||
*
|
|
||||||
* @apiNote Nonsensical input such as a Windows file path with a drive
|
|
||||||
* letter cannot be disambiguated from an absolute URL so will be rejected
|
|
||||||
* (by returning null) by this method.
|
|
||||||
*
|
|
||||||
* @return the resolved URL or null if the input is an absolute URL with
|
* @return the resolved URL or null if the input is an absolute URL with
|
||||||
* a scheme other than file (ignoring case)
|
* a scheme other than file (ignoring case)
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
*/
|
*/
|
||||||
static URL tryResolveFile(URL base, String input) throws MalformedURLException {
|
static URL tryResolveFile(URL base, String input) throws MalformedURLException {
|
||||||
int index = input.indexOf(':');
|
URL retVal = new URL(base, input);
|
||||||
boolean isFile;
|
if (input.indexOf(':') >= 0 &&
|
||||||
if (index >= 0) {
|
!"file".equalsIgnoreCase(retVal.getProtocol())) {
|
||||||
String scheme = input.substring(0, index);
|
// 'input' contains a ':', which might be a scheme, or might be
|
||||||
isFile = "file".equalsIgnoreCase(scheme);
|
// a Windows drive letter. If the protocol for the resolved URL
|
||||||
} else {
|
// isn't "file:", it should be ignored.
|
||||||
isFile = true;
|
return null;
|
||||||
}
|
}
|
||||||
return (isFile) ? new URL(base, input) : null;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,8 +33,8 @@ import jdk.test.lib.compiler.InMemoryJavaCompiler;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8216401
|
* @bug 8216401 8235361
|
||||||
* @summary Test loading of JAR Class-Path entry with file: scheme
|
* @summary Test classloading via JAR Class-Path entries
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
*
|
*
|
||||||
* @run main/othervm JarClassPathFileEntry
|
* @run main/othervm JarClassPathFileEntry
|
||||||
@ -52,6 +52,19 @@ public class JarClassPathFileEntry {
|
|||||||
private final static Path CONTEXT_JAR_PATH = Paths.get(TEST_CLASSES, "Context.jar");
|
private final static Path CONTEXT_JAR_PATH = Paths.get(TEST_CLASSES, "Context.jar");
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
|
String fileScheme = "file:" + (IS_WINDOWS ? toUnixPath(OTHER_JAR_PATH.toString())
|
||||||
|
: OTHER_JAR_PATH.toString());
|
||||||
|
doTest(fileScheme);
|
||||||
|
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
// Relative URL encoding of absolute path, e.g. /C:\\path\\to\\file.jar
|
||||||
|
String driveLetter = "/" + OTHER_JAR_PATH;
|
||||||
|
doTest(driveLetter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Load a class from Other.jar via the given Class-Path entry */
|
||||||
|
private static void doTest(String classPathEntry) throws Throwable {
|
||||||
// Create Other.class in OTHER_DIR, off the default classpath
|
// Create Other.class in OTHER_DIR, off the default classpath
|
||||||
byte klassbuf[] = InMemoryJavaCompiler.compile("Other",
|
byte klassbuf[] = InMemoryJavaCompiler.compile("Other",
|
||||||
"public class Other {}");
|
"public class Other {}");
|
||||||
@ -72,8 +85,6 @@ public class JarClassPathFileEntry {
|
|||||||
Attributes attrs = mf.getMainAttributes();
|
Attributes attrs = mf.getMainAttributes();
|
||||||
attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
||||||
|
|
||||||
String classPathEntry = "file:" + (IS_WINDOWS ? toUnixPath(OTHER_JAR_PATH.toString())
|
|
||||||
: OTHER_JAR_PATH.toString());
|
|
||||||
attrs.put(Attributes.Name.CLASS_PATH, classPathEntry);
|
attrs.put(Attributes.Name.CLASS_PATH, classPathEntry);
|
||||||
|
|
||||||
System.out.println("Creating Context.jar with Class-Path: " + classPathEntry);
|
System.out.println("Creating Context.jar with Class-Path: " + classPathEntry);
|
||||||
|
Loading…
Reference in New Issue
Block a user