8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")

Use URL constructor for jrt URL in SystemDictionaryShared::get_shared_protection_domain().

Reviewed-by: ccheung, iklam, dholmes, coleenp
This commit is contained in:
Jiangli Zhou 2019-01-10 13:03:34 -05:00
parent 796c514237
commit e0aa3e0609
5 changed files with 39 additions and 32 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 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
@ -503,26 +503,33 @@ Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader,
Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader,
ModuleEntry* mod, TRAPS) {
ClassLoaderData *loader_data = mod->loader_data();
Handle protection_domain;
if (mod->shared_protection_domain() == NULL) {
Symbol* location = mod->location();
if (location != NULL) {
Handle url_string = java_lang_String::create_from_symbol(
location, CHECK_(protection_domain));
Handle location_string = java_lang_String::create_from_symbol(
location, CHECK_NH);
Handle url;
JavaValue result(T_OBJECT);
Klass* classLoaders_klass =
SystemDictionary::jdk_internal_loader_ClassLoaders_klass();
JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(),
if (location->starts_with("jrt:/")) {
url = JavaCalls::construct_new_instance(SystemDictionary::URL_klass(),
vmSymbols::string_void_signature(),
location_string, CHECK_NH);
} else {
Klass* classLoaders_klass =
SystemDictionary::jdk_internal_loader_ClassLoaders_klass();
JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(),
vmSymbols::toFileURL_signature(),
url_string, CHECK_(protection_domain));
Handle url = Handle(THREAD, (oop)result.get_jobject());
location_string, CHECK_NH);
url = Handle(THREAD, (oop)result.get_jobject());
}
Handle pd = get_protection_domain_from_classloader(class_loader, url, THREAD);
Handle pd = get_protection_domain_from_classloader(class_loader, url,
CHECK_NH);
mod->set_shared_protection_domain(loader_data, pd);
}
}
protection_domain = Handle(THREAD, mod->shared_protection_domain());
Handle protection_domain(THREAD, mod->shared_protection_domain());
assert(protection_domain.not_null(), "sanity");
return protection_domain;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 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
@ -48,25 +48,24 @@ public class ProtectionDomain {
TestCommon.list("ProtDomain",
"ProtDomainBOther",
"java/util/Dictionary",
"sun/tools/javac/Main",
"com/sun/tools/javac/Main",
"jdk/nio/zipfs/ZipInfo",
"java/net/URL",
"sun/rmi/rmic/Main",
"com/sun/jndi/dns/DnsName"));
OutputAnalyzer output;
// First class is loaded from CDS, second class is loaded from JAR
output = TestCommon.exec(appJar, "ProtDomain");
TestCommon.checkExec(output, "Protection Domains match");
TestCommon.run("-cp", appJar, "ProtDomain")
.assertNormalExit("Protection Domains match");
// First class is loaded from JAR, second class is loaded from CDS
output = TestCommon.exec(appJar, "ProtDomainB");
TestCommon.checkExec(output, "Protection Domains match");
TestCommon.run("-cp", appJar, "ProtDomainB")
.assertNormalExit("Protection Domains match");
// Test ProtectionDomain for application and extension module classes from the
// "modules" jimage
output = TestCommon.exec(appJar, "JimageClassProtDomain");
output.shouldNotContain("Failed: Protection Domains do not match");
TestCommon.run("-cp", appJar, "JimageClassProtDomain")
.assertNormalExit(output -> output.shouldNotContain(
"Failed: Protection Domains do not match"));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2018, 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
@ -37,7 +37,7 @@ public class JimageClassProtDomain {
"java.util.Dictionary", "java.util.ServiceConfigurationError"},
{"Loading shared app module class first",
"sun.tools.javac.Main", "sun.tools.javac.BatchParser"},
"com.sun.tools.javac.Main", "com.sun.tools.javac.code.Symbol"},
{"Loading shared ext module class first",
"jdk.nio.zipfs.ZipInfo", "jdk.nio.zipfs.ZipPath"},
@ -46,7 +46,7 @@ public class JimageClassProtDomain {
"java.net.HttpCookie", "java.net.URL"},
{"Loading non-shared app module class first",
"sun.rmi.rmic.RMIGenerator", "sun.rmi.rmic.Main"},
"com.sun.tools.sjavac.Util", "com.sun.tools.sjavac.Main"},
{"Loading non-shared ext module class first",
"com.sun.jndi.dns.Resolver", "com.sun.jndi.dns.DnsName"}};
@ -61,13 +61,16 @@ public class JimageClassProtDomain {
Class c1 = Class.forName(shared);
Class c2 = Class.forName(nonShared);
if (c1.getProtectionDomain() != c2.getProtectionDomain()) {
System.out.println("Failed: Protection Domains do not match!");
System.out.println(c1.getProtectionDomain());
System.out.println(c1.getProtectionDomain().getCodeSource());
System.out.println(c2.getProtectionDomain());
System.out.println(c2.getProtectionDomain().getCodeSource());
System.exit(1);
throw new RuntimeException("Failed: Protection Domains do not match!");
} else {
System.out.println(c1.getProtectionDomain());
System.out.println(c1.getProtectionDomain().getCodeSource());
System.out.println(c2.getProtectionDomain());
System.out.println(c2.getProtectionDomain().getCodeSource());
System.out.println("Passed: Protection Domains match.");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, 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
@ -42,8 +42,7 @@ public class ProtDomain {
if (mine == his) {
System.out.println("Protection Domains match");
} else {
System.out.println("Protection Domains do not match!");
System.exit(1);
throw new RuntimeException("Protection Domains do not match!");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, 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
@ -42,8 +42,7 @@ public class ProtDomainB {
if (mine == his) {
System.out.println("Protection Domains match");
} else {
System.out.println("Protection Domains do not match!");
System.exit(1);
throw new RuntimeException("Protection Domains do not match!");
}
}
}