test/java/util/logging/bundlesearch/IndirectlyLoadABundle.java
Print this page
rev 7022 : 8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
Summary: Use caller's classloader to load resource as an alternative to thread context classloader and system classloader
Reviewed-by: duke
*** 27,53 ****
import java.net.URLClassLoader;
import java.nio.file.Paths;
/**
* This class is used to ensure that a resource bundle loadable by a classloader
! * is on the caller's stack, but not on the classpath or TCCL to ensure that
! * Logger.getLogger() can't load the bundle via a stack search
*
* @author Jim Gish
*/
public class IndirectlyLoadABundle {
! private final static String rbName = "StackSearchableResource";
public boolean loadAndTest() throws Throwable {
// Find out where we are running from so we can setup the URLClassLoader URLs
// test.src and test.classes will be set if running in jtreg, but probably
// not otherwise
String testDir = System.getProperty("test.src", System.getProperty("user.dir"));
String testClassesDir = System.getProperty("test.classes",
System.getProperty("user.dir"));
- String sep = System.getProperty("file.separator");
URL[] urls = new URL[2];
// Allow for both jtreg and standalone cases here
urls[0] = Paths.get(testDir, "resources").toUri().toURL();
--- 27,52 ----
import java.net.URLClassLoader;
import java.nio.file.Paths;
/**
* This class is used to ensure that a resource bundle loadable by a classloader
! * is on the caller's stack, but not on the classpath or TCCL. It tests that
! * Logger.getLogger() can load the bundle via the immediate caller's classloader
*
* @author Jim Gish
*/
public class IndirectlyLoadABundle {
! private final static String rbName = "CallerSearchableResource";
public boolean loadAndTest() throws Throwable {
// Find out where we are running from so we can setup the URLClassLoader URLs
// test.src and test.classes will be set if running in jtreg, but probably
// not otherwise
String testDir = System.getProperty("test.src", System.getProperty("user.dir"));
String testClassesDir = System.getProperty("test.classes",
System.getProperty("user.dir"));
URL[] urls = new URL[2];
// Allow for both jtreg and standalone cases here
urls[0] = Paths.get(testDir, "resources").toUri().toURL();
*** 68,78 ****
throw new Exception("Was able to directly load bundle " + rbName
+ " from " + myCL + " but shouldn't have been"
+ " able to. Test config problem");
}
! Class<?> loadItUpClazz = Class.forName("LoadItUp", true, yetAnotherResourceCL);
ClassLoader actual = loadItUpClazz.getClassLoader();
if (actual != yetAnotherResourceCL) {
throw new Exception("LoadItUp was loaded by an unexpected CL: " + actual);
}
Object loadItUp = loadItUpClazz.newInstance();
--- 67,77 ----
throw new Exception("Was able to directly load bundle " + rbName
+ " from " + myCL + " but shouldn't have been"
+ " able to. Test config problem");
}
! Class<?> loadItUpClazz = Class.forName("LoadItUp1", true, yetAnotherResourceCL);
ClassLoader actual = loadItUpClazz.getClassLoader();
if (actual != yetAnotherResourceCL) {
throw new Exception("LoadItUp was loaded by an unexpected CL: " + actual);
}
Object loadItUp = loadItUpClazz.newInstance();