|
@@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.tooling.muzzle.matcher;
|
|
|
|
|
|
import static java.util.Collections.emptyList;
|
|
|
import static java.util.Collections.singletonList;
|
|
|
-import static net.bytebuddy.dynamic.loading.ClassLoadingStrategy.BOOTSTRAP_LOADER;
|
|
|
|
|
|
import io.opentelemetry.instrumentation.api.caching.Cache;
|
|
|
import io.opentelemetry.javaagent.extension.muzzle.ClassRef;
|
|
@@ -15,7 +14,6 @@ import io.opentelemetry.javaagent.extension.muzzle.FieldRef;
|
|
|
import io.opentelemetry.javaagent.extension.muzzle.Flag;
|
|
|
import io.opentelemetry.javaagent.extension.muzzle.MethodRef;
|
|
|
import io.opentelemetry.javaagent.tooling.AgentTooling;
|
|
|
-import io.opentelemetry.javaagent.tooling.Utils;
|
|
|
import io.opentelemetry.javaagent.tooling.muzzle.InstrumentationClassPredicate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
@@ -53,16 +51,15 @@ public final class ReferenceMatcher {
|
|
|
/**
|
|
|
* Matcher used by ByteBuddy. Fails fast and only caches empty results, or complete results
|
|
|
*
|
|
|
- * @param userClassLoader Classloader to validate against (or null for bootstrap)
|
|
|
+ * @param userClassLoader Classloader to validate against (cannot be {@code null}, must pass
|
|
|
+ * "bootstrap proxy" instead of bootstrap class loader)
|
|
|
* @return true if all references match the classpath of loader
|
|
|
*/
|
|
|
public boolean matches(ClassLoader userClassLoader) {
|
|
|
- if (userClassLoader == BOOTSTRAP_LOADER) {
|
|
|
- userClassLoader = Utils.getBootstrapProxy();
|
|
|
- }
|
|
|
return mismatchCache.computeIfAbsent(userClassLoader, this::doesMatch);
|
|
|
}
|
|
|
|
|
|
+ // loader cannot be null, must pass "bootstrap proxy" instead of bootstrap class loader
|
|
|
private boolean doesMatch(ClassLoader loader) {
|
|
|
TypePool typePool = createTypePool(loader);
|
|
|
for (ClassRef reference : references.values()) {
|
|
@@ -76,13 +73,11 @@ public final class ReferenceMatcher {
|
|
|
/**
|
|
|
* Loads the full list of mismatches. Used in debug contexts only
|
|
|
*
|
|
|
- * @param loader Classloader to validate against (or null for bootstrap)
|
|
|
+ * @param loader Classloader to validate against (cannot be {@code null}, must pass "bootstrap *
|
|
|
+ * proxy" instead of bootstrap class loader)
|
|
|
* @return A list of all mismatches between this ReferenceMatcher and loader's classpath.
|
|
|
*/
|
|
|
public List<Mismatch> getMismatchedReferenceSources(ClassLoader loader) {
|
|
|
- if (loader == BOOTSTRAP_LOADER) {
|
|
|
- loader = Utils.getBootstrapProxy();
|
|
|
- }
|
|
|
TypePool typePool = createTypePool(loader);
|
|
|
|
|
|
List<Mismatch> mismatches = emptyList();
|
|
@@ -94,7 +89,9 @@ public final class ReferenceMatcher {
|
|
|
return mismatches;
|
|
|
}
|
|
|
|
|
|
+ // loader cannot be null, must pass "bootstrap proxy" instead of bootstrap class loader
|
|
|
private static TypePool createTypePool(ClassLoader loader) {
|
|
|
+ // ok to use locationStrategy() without fallback bootstrap proxy here since loader is non-null
|
|
|
return AgentTooling.poolStrategy()
|
|
|
.typePool(AgentTooling.locationStrategy().classFileLocator(loader), loader);
|
|
|
}
|