Skip to content

Commit

Permalink
make findLoadedClass accessible on java17
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Apr 1, 2022
1 parent 45dec55 commit bf1c29f
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.instrumentation.api.cache.Cache;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.bootstrap.InstrumentationHolder;
import io.opentelemetry.javaagent.bootstrap.VirtualFieldAccessorMarker;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
Expand All @@ -21,7 +22,9 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.TypeList;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.loading.ClassInjector;
import net.bytebuddy.pool.TypePool;
import net.bytebuddy.utility.JavaModule;

/**
*
Expand Down Expand Up @@ -78,6 +81,20 @@ public AgentCachingPoolStrategy(AgentLocationStrategy locationStrategy) {
}

private static Method getFindLoadedClassMethod() {
if (JavaModule.isSupported()) {
JavaModule currentModule = JavaModule.ofType(AgentCachingPoolStrategy.class);
JavaModule javaBase = JavaModule.ofType(ClassLoader.class);
if (javaBase != null && javaBase.isNamed() && currentModule != null) {
ClassInjector.UsingInstrumentation.redefineModule(
InstrumentationHolder.getInstrumentation(),
javaBase,
Collections.emptySet(),
Collections.emptyMap(),
Collections.singletonMap("java.lang", Collections.singleton(currentModule)),
Collections.emptySet(),
Collections.emptyMap());
}
}
try {
Method method = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class);
method.setAccessible(true);
Expand Down

0 comments on commit bf1c29f

Please sign in to comment.