Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make java.sql classes available to the agent and extensions #7038

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public AgentClassLoader(File javaagentFile, String internalJarFileName) {

private static ClassLoader getParentClassLoader() {
if (JAVA_VERSION > 8) {
return new JdkHttpServerClassLoader();
return new PlatformDelegatingClassLoader();
}
return null;
}
Expand Down Expand Up @@ -441,7 +441,10 @@ public long getContentLengthLong() {
}
}

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

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

private final ClassLoader platformClassLoader = getPlatformLoader();

public JdkHttpServerClassLoader() {
public PlatformDelegatingClassLoader() {
super(null);
}

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