Create muzzle references from ldc instructions
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/ReferenceCreator.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/muzzle/ReferenceCreator.java
@@ -347,5 +347,20 @@ public class ReferenceCreator extends ClassVisitor {
.build());
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
}
+
+ @Override
+ public void visitLdcInsn(final Object value) {
+ if (value instanceof Type) {
+ final Type type = underlyingType((Type) value);
+ if (type.getSort() == Type.OBJECT) {
+ addReference(
+ new Reference.Builder(type.getInternalName())
+ .withSource(refSourceClassName, currentLineNumber)
+ .withFlag(computeMinimumClassAccess(refSourceType, type))
+ .build());
+ }
+ }
+ super.visitLdcInsn(value);
+ }
}
}

MODIFY
dd-java-agent/testing/src/test/groovy/muzzle/ReferenceCreatorTest.groovy
dd-java-agent/testing/src/test/groovy/muzzle/ReferenceCreatorTest.groovy
@@ -57,6 +57,14 @@ class ReferenceCreatorTest extends AgentTestRunner {
findMethod(bMethods, "protectedMethod", "()V").getFlags().contains(Reference.Flag.PROTECTED_OR_HIGHER)
}
+ def "ldc creates references" () {
+ setup:
+ Map<String, Reference> references = ReferenceCreator.createReferencesFrom(LdcAdvice.getName(), this.getClass().getClassLoader())
+
+ expect:
+ references.get('muzzle.TestClasses$MethodBodyAdvice$A') != null
+ }
+
private static Reference.Method findMethod(Set<Reference.Method> methods, String methodName, String methodDesc) {
for (Reference.Method method : methods) {
if (method == new Reference.Method(methodName, methodDesc)) {

MODIFY
dd-java-agent/testing/src/test/java/muzzle/TestClasses.java
dd-java-agent/testing/src/test/java/muzzle/TestClasses.java
@@ -68,4 +68,10 @@ public class TestClasses {
public interface AnotherInterface extends SomeInterface {}
}
+
+ public static class LdcAdvice {
+ public static void ldcMethod() {
+ MethodBodyAdvice.A.class.getName();
+ }
+ }
}

Create muzzle references from ldc instructions