author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 17487 | 77566e5979d1 |
permissions | -rw-r--r-- |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
1 |
/* |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
4 |
* |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
8 |
* |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
13 |
* accompanied this code). |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
14 |
* |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
18 |
* |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
21 |
* questions. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
22 |
*/ |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
23 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
24 |
import java.lang.reflect.InvocationTargetException; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
25 |
import java.lang.reflect.Method; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
26 |
import java.net.URL; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
27 |
import java.net.URLClassLoader; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
28 |
import java.nio.file.Paths; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
29 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
30 |
/** |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
31 |
* This class constructs a scenario where a bundle is accessible on the call |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
32 |
* stack two levels up from the call to getLogger(), but not on the immediate |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
33 |
* caller. This tests that getLogger() isn't doing a stack crawl more than one |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
34 |
* level up to find a bundle. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
35 |
* |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
36 |
* @author Jim Gish |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
37 |
*/ |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
38 |
public class TwiceIndirectlyLoadABundle { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
39 |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
17487
diff
changeset
|
40 |
private static final String rbName = "StackSearchableResource"; |
17487
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
41 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
42 |
public boolean loadAndTest() throws Throwable { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
43 |
// Find out where we are running from so we can setup the URLClassLoader URLs |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
44 |
// test.src and test.classes will be set if running in jtreg, but probably |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
45 |
// not otherwise |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
46 |
String testDir = System.getProperty("test.src", System.getProperty("user.dir")); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
47 |
String testClassesDir = System.getProperty("test.classes", |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
48 |
System.getProperty("user.dir")); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
49 |
URL[] urls = new URL[2]; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
50 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
51 |
// Allow for both jtreg and standalone cases here |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
52 |
// Unlike the 1-level test where we can get the bundle from the caller's |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
53 |
// class loader, for this one we don't want to expose the resource directory |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
54 |
// to the next class. That way we're invoking the LoadItUp2Invoker class |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
55 |
// from this class that does have access to the resources (two levels |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
56 |
// up the call stack), but the Invoker itself won't have access to resource |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
57 |
urls[0] = Paths.get(testDir,"resources").toUri().toURL(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
58 |
urls[1] = Paths.get(testClassesDir).toUri().toURL(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
59 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
60 |
// Make sure we can find it via the URLClassLoader |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
61 |
URLClassLoader yetAnotherResourceCL = new URLClassLoader(urls, null); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
62 |
Class<?> loadItUp2InvokerClazz = Class.forName("LoadItUp2Invoker", true, |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
63 |
yetAnotherResourceCL); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
64 |
ClassLoader actual = loadItUp2InvokerClazz.getClassLoader(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
65 |
if (actual != yetAnotherResourceCL) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
66 |
throw new Exception("LoadItUp2Invoker was loaded by an unexpected CL: " |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
67 |
+ actual); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
68 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
69 |
Object loadItUp2Invoker = loadItUp2InvokerClazz.newInstance(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
70 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
71 |
Method setupMethod = loadItUp2InvokerClazz.getMethod("setup", |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
72 |
urls.getClass(), String.class); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
73 |
try { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
74 |
// For the next class loader we create, we want to leave off |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
75 |
// the resources. That way loadItUp2Invoker will have access to |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
76 |
// them, but the next class won't. |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
77 |
URL[] noResourceUrl = new URL[1]; |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
78 |
noResourceUrl[0] = urls[1]; // from above -- just the test classes |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
79 |
setupMethod.invoke(loadItUp2Invoker, noResourceUrl, rbName); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
80 |
} catch (InvocationTargetException ex) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
81 |
throw ex.getTargetException(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
82 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
83 |
|
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
84 |
Method testMethod = loadItUp2InvokerClazz.getMethod("test"); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
85 |
try { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
86 |
return (Boolean) testMethod.invoke(loadItUp2Invoker); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
87 |
} catch (InvocationTargetException ex) { |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
88 |
throw ex.getTargetException(); |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
89 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
90 |
} |
77566e5979d1
8013380: Removal of stack walk to find resource bundle breaks Glassfish startup
jgish
parents:
diff
changeset
|
91 |
} |