Skip to content

Commit 2a2f7cd

Browse files
authored
Make java.sql classes available to the agent and extensions (open-telemetry#7038)
Resolves open-telemetry#7037
1 parent 6f9ca0b commit 2a2f7cd

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/AgentClassLoader.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public AgentClassLoader(File javaagentFile, String internalJarFileName) {
116116

117117
private static ClassLoader getParentClassLoader() {
118118
if (JAVA_VERSION > 8) {
119-
return new JdkHttpServerClassLoader();
119+
return new PlatformDelegatingClassLoader();
120120
}
121121
return null;
122122
}
@@ -441,7 +441,10 @@ public long getContentLengthLong() {
441441
}
442442
}
443443

444-
private static class JdkHttpServerClassLoader extends ClassLoader {
444+
// We don't always delegate to platform loader because platform class loader also contains user
445+
// classes when running a modular application. We don't want these classes interfering with the
446+
// agent.
447+
private static class PlatformDelegatingClassLoader extends ClassLoader {
445448

446449
static {
447450
// this class loader doesn't load any classes, so this is technically unnecessary,
@@ -452,14 +455,16 @@ private static class JdkHttpServerClassLoader extends ClassLoader {
452455

453456
private final ClassLoader platformClassLoader = getPlatformLoader();
454457

455-
public JdkHttpServerClassLoader() {
458+
public PlatformDelegatingClassLoader() {
456459
super(null);
457460
}
458461

459462
@Override
460463
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
461464
// prometheus exporter uses jdk http server, load it from the platform class loader
462-
if (name != null && name.startsWith("com.sun.net.httpserver.")) {
465+
// some custom extensions use java.sql classes, make these available to agent and extensions
466+
if (name != null
467+
&& (name.startsWith("com.sun.net.httpserver.") || name.startsWith("java.sql."))) {
463468
return platformClassLoader.loadClass(name);
464469
}
465470
return Class.forName(name, false, null);

0 commit comments

Comments
 (0)