Skip to content

Commit

Permalink
Merge pull request #1 from JonasKunz/indy-reflection-recursion
Browse files Browse the repository at this point in the history
Replace reflection with MethodHandles usage in indy bootstraping
  • Loading branch information
SylvainJuge authored Aug 30, 2024
2 parents ad7440f + 96f0356 commit 6747406
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,15 @@ public MethodHandles.Lookup getLookup() {
if (cachedLookup == null) {
// Load the injected copy of LookupExposer and invoke it
try {
MethodType getLookupType = MethodType.methodType(MethodHandles.Lookup.class);
// we don't mind the race condition causing the initialization to run multiple times here
Class<?> lookupExposer = loadClass(LookupExposer.class.getName());
cachedLookup = (MethodHandles.Lookup) lookupExposer.getMethod("getLookup").invoke(null);
} catch (Exception e) {
// Note: we must use MethodHandles instead of reflection here to avoid a recursion
// for our internal ReflectionInstrumentationModule which instruments reflection methods
cachedLookup = (MethodHandles.Lookup) MethodHandles.publicLookup()
.findStatic(lookupExposer, "getLookup", getLookupType)
.invoke();
} catch (Throwable e) {
throw new IllegalStateException(e);
}
}
Expand Down

0 comments on commit 6747406

Please sign in to comment.