Skip to content

Commit

Permalink
Make ClassLoaderValue compatible with PowerMock (#402)
Browse files Browse the repository at this point in the history
(cherry picked from commit 981fdd9)
  • Loading branch information
jglick authored and basil committed Aug 25, 2022
1 parent 567a69e commit c400cfb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/org/kohsuke/stapler/ClassLoaderValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ protected T computeValue(Class<?> type) {
public interface X {}

public final T get(ClassLoader cl) {
Class<?> x;
try {
cl.loadClass(X.class.getName());
// OK, X is visible to cl, can use trick
} catch (ClassNotFoundException x) {
x = cl.loadClass(X.class.getName());
// OK, X is visible to cl, can use trick; note that x != X.class when using PowerMock
} catch (ClassNotFoundException e) {
// fallback, no caching; could use WeakHashMap though typically values would strongly hold keys so both could leak
return computeValue(cl);
}
Class<?> type = Proxy.getProxyClass(cl, X.class);
Class<?> type = Proxy.getProxyClass(cl, x);
assert type.getClassLoader() == cl;
return storage.get(type);
}
Expand Down

0 comments on commit c400cfb

Please sign in to comment.