Skip to content
Merged
Show file tree
Hide file tree
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 @@ -199,7 +199,8 @@ private static BiFunction injectViaLoadClass(Instrumentation inst) throws Except
try {
inst.addTransformer(injectGlue, true);
inst.retransformClasses(ClassLoader.class);
return (BiFunction) getSystemClassLoader().loadClass(DefineClassGlue.ID).newInstance();
Class<?> glueClass = getSystemClassLoader().loadClass(DefineClassGlue.ID);
return (BiFunction) glueClass.getConstructor().newInstance();
} finally {
// remove temporary ClassLoader.loadClass patch
inst.removeTransformer(injectGlue);
Expand All @@ -219,7 +220,8 @@ private static BiFunction injectViaForName(Instrumentation inst) throws Exceptio
try {
inst.addTransformer(injectGlue, true);
inst.retransformClasses(Class.class);
return (BiFunction) Class.forName(DefineClassGlue.ID).newInstance();
Class<?> glueClass = Class.forName(DefineClassGlue.ID);
return (BiFunction) glueClass.getConstructor().newInstance();
} finally {
// remove temporary Class.forName patch
inst.removeTransformer(injectGlue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.lang.reflect.ReflectPermission;
import java.security.CodeSource;
import java.security.Permission;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -18,8 +17,8 @@ public static void premain(String arguments, Instrumentation inst) {
AtomicInteger retransforms = new AtomicInteger();
ClassFileTransformer observer = observeRetransforms(retransforms);
inst.addTransformer(observer, true);
Policy.setPolicy(
new Policy() {
java.security.Policy.setPolicy(
new java.security.Policy() {
@Override
public boolean implies(ProtectionDomain domain, Permission permission) {
CodeSource source = domain.getCodeSource();
Expand Down
14 changes: 12 additions & 2 deletions testing/src/main/java/datadog/instrument/testing/TestAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ public final class TestAgent {

private TestAgent() {}

/** Called by the JVM when the testing jar is supplied with {@code -javaagent}. */
/**
* Called by the JVM when the testing jar is supplied with {@code -javaagent}.
*
* @param arguments the agent arguments (unused)
* @param inst the instrumentation instance supplied by the JVM
*/
public static void premain(String arguments, Instrumentation inst) {
instrumentation = inst;
}

/** Returns the instrumentation supplied at JVM startup. */
/**
* Returns the instrumentation supplied at JVM startup.
*
* @return the instrumentation instance supplied by the JVM
* @throws IllegalStateException if the testing jar was not supplied with {@code -javaagent}
*/
public static Instrumentation getInstrumentation() {
if (instrumentation == null) {
throw new IllegalStateException("The testing jar must be supplied with -javaagent");
Expand Down