Skip to content

Commit 848c87f

Browse files
committed
fix build
1 parent 1eb77ee commit 848c87f

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyModuleRegistry.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.HashMap;
1616
import java.util.Map;
1717
import java.util.concurrent.ConcurrentHashMap;
18+
import javax.annotation.Nullable;
1819
import net.bytebuddy.agent.builder.AgentBuilder;
1920
import net.bytebuddy.utility.JavaModule;
2021

@@ -57,16 +58,8 @@ public static InstrumentationModuleClassLoader getInstrumentationClassLoader(
5758
InstrumentationModule module, ClassLoader instrumentedClassLoader) {
5859

5960
ClassLoader moduleCl = module.getClass().getClassLoader();
60-
InstrumentationModuleClassLoader loader = null;
61-
if (!(moduleCl instanceof ExtensionClassLoader)) {
62-
loader = instrumentationClassLoaders.get(instrumentedClassLoader);
63-
} else {
64-
Map<ClassLoader, InstrumentationModuleClassLoader> map =
65-
extensionsInstrumentationClassLoaders.get(moduleCl);
66-
if (map != null) {
67-
loader = map.get(instrumentedClassLoader);
68-
}
69-
}
61+
InstrumentationModuleClassLoader loader =
62+
lookupInstrumentationClassLoader(instrumentedClassLoader, moduleCl);
7063

7164
if (loader == null || !loader.hasModuleInstalled(module)) {
7265
throw new IllegalArgumentException(
@@ -97,6 +90,22 @@ public static InstrumentationModuleClassLoader getInstrumentationClassLoader(
9790
return loader;
9891
}
9992

93+
@Nullable
94+
private static InstrumentationModuleClassLoader lookupInstrumentationClassLoader(
95+
ClassLoader instrumentedClassLoader, ClassLoader moduleCl) {
96+
if (!(moduleCl instanceof ExtensionClassLoader)) {
97+
// internal instrumentation is using one CL per instrumented CL.
98+
return instrumentationClassLoaders.get(instrumentedClassLoader);
99+
}
100+
// extension module needs to use a common CL per extension and instrumented CL.
101+
Map<ClassLoader, InstrumentationModuleClassLoader> map =
102+
extensionsInstrumentationClassLoaders.get(moduleCl);
103+
if (map != null) {
104+
return map.get(instrumentedClassLoader);
105+
}
106+
return null;
107+
}
108+
100109
/**
101110
* Returns a newly created class loader containing only the provided module. Note that other
102111
* modules from the same module group will not be installed in this class loader.

0 commit comments

Comments
 (0)