JMXFetch loading threw permission errors
MODIFY
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/DatadogClassLoader.java
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/DatadogClassLoader.java
@@ -10,6 +10,7 @@ import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.nio.file.NoSuchFileException;
+import java.security.Permission;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarEntry;
@@ -148,10 +149,16 @@ public class DatadogClassLoader extends URLClassLoader {
@Override
protected URLConnection openConnection(final URL url) throws IOException {
+ if (url.getFile().equals("/")) {
+ // "/" is used as the default url of the jar
+ // This is called by the SecureClassLoader trying to obtain permissions
+ return new InternalJarURLConnection(url, new byte[] {});
+ }
+
final byte[] bytes = filenameToBytes.get(url.getFile());
if (bytes == null) {
- throw new NoSuchFileException(url.getFile());
+ throw new NoSuchFileException(url.getFile(), null, url.getFile() + " not in internal jar");
}
return new InternalJarURLConnection(url, bytes);
@@ -175,6 +182,12 @@ public class DatadogClassLoader extends URLClassLoader {
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(bytes);
}
+
+ @Override
+ public Permission getPermission() {
+ // No permissions needed because all classes are in memory
+ return null;
+ }
}
/**

MODIFY
dd-java-agent/src/main/java/datadog/trace/agent/TracingAgent.java
dd-java-agent/src/main/java/datadog/trace/agent/TracingAgent.java
@@ -53,9 +53,19 @@ public class TracingAgent {
final Method registerCallbackMethod =
agentInstallerClass.getMethod("registerClassLoadCallback", String.class, Runnable.class);
registerCallbackMethod.invoke(
- null,
- "java.util.logging.LogManager",
- new Runnable() {
+ null, "java.util.logging.LogManager", new LoggingCallback(inst));
+ } else {
+ startJmxFetch(inst);
+ }
+ }
+
+ protected static class LoggingCallback implements Runnable {
+ private final Instrumentation inst;
+
+ public LoggingCallback(final Instrumentation inst) {
+ this.inst = inst;
+ }
+
@Override
public void run() {
try {
@@ -64,10 +74,6 @@ public class TracingAgent {
throw new RuntimeException(e);
}
}
- });
- } else {
- startJmxFetch(inst);
- }
}
public static synchronized void startDatadogAgent(final Instrumentation inst) throws Exception {

JMXFetch loading threw permission errors