Skip to content

Commit 981fdd9

Browse files
authored
Make ClassLoaderValue compatible with PowerMock (#402)
1 parent fb8f9a7 commit 981fdd9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/main/java/org/kohsuke/stapler/ClassLoaderValue.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ protected T computeValue(Class<?> type) {
4545
public interface X {}
4646

4747
public final T get(ClassLoader cl) {
48+
Class<?> x;
4849
try {
49-
cl.loadClass(X.class.getName());
50-
// OK, X is visible to cl, can use trick
51-
} catch (ClassNotFoundException x) {
50+
x = cl.loadClass(X.class.getName());
51+
// OK, X is visible to cl, can use trick; note that x != X.class when using PowerMock
52+
} catch (ClassNotFoundException e) {
5253
// fallback, no caching; could use WeakHashMap though typically values would strongly hold keys so both could leak
5354
return computeValue(cl);
5455
}
55-
Class<?> type = Proxy.getProxyClass(cl, X.class);
56+
Class<?> type = Proxy.getProxyClass(cl, x);
5657
assert type.getClassLoader() == cl;
5758
return storage.get(type);
5859
}

0 commit comments

Comments
 (0)