diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java index 18f9adf76f1..ffcb5a006f0 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java @@ -275,7 +275,9 @@ public byte[] transform( return null; } ClassNode classNode = parseClassFile(classFilePath, classfileBuffer); - checkMethodParameters(classNode); + if (!checkMethodParameters(classNode, definitions, fullyQualifiedClassName)) { + return null; + } if (!checkRecordTypeAnnotation(classNode, definitions, fullyQualifiedClassName)) { return null; } @@ -306,10 +308,11 @@ public byte[] transform( * instrumented the class, we will retransform for removing the instrumentation and then the * attribute is stripped. That's why we are preventing it even at load time. */ - private void checkMethodParameters(ClassNode classNode) { + private boolean checkMethodParameters( + ClassNode classNode, List definitions, String fullyQualifiedClassName) { if (JAVA_AT_LEAST_19) { // bug is fixed since JDK19, no need to perform check - return; + return true; } boolean isRecord = ASMHelper.isRecord(classNode); // capping scanning of methods to 100 to avoid generated class with thousand of methods @@ -328,13 +331,17 @@ private void checkMethodParameters(ClassNode classNode) { if (methodNode.parameters != null && !methodNode.parameters.isEmpty() && SpringHelper.isSpringUsingOnlyMethodParameters(DebuggerAgent.getInstrumentation())) { - throw new RuntimeException( + reportInstrumentationFails( + definitions, + fullyQualifiedClassName, "Method Parameters attribute detected, instrumentation not supported"); + return false; } else { // we found at leat a method with one parameter if name is not present we can stop there break; } } + return true; } /* diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/sink/DebuggerSink.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/sink/DebuggerSink.java index 3c4e063c184..5c91e110acb 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/sink/DebuggerSink.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/sink/DebuggerSink.java @@ -220,13 +220,11 @@ public void addDiagnostics(ProbeId probeId, List messages) { for (DiagnosticMessage msg : messages) { switch (msg.getKind()) { case INFO: - LOGGER.info(msg.getMessage()); - break; case WARN: - LOGGER.warn(msg.getMessage()); + LOGGER.debug(msg.getMessage()); break; case ERROR: - LOGGER.error(msg.getMessage()); + LOGGER.debug(msg.getMessage()); reportError(probeId, msg); break; } diff --git a/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java b/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java index fab74757970..a63114c2516 100644 --- a/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java +++ b/dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java @@ -3059,7 +3059,7 @@ public void methodParametersAttribute() throws Exception { verify(probeStatusSink, times(1)).addError(probeIdCaptor.capture(), strCaptor.capture()); assertEquals(PROBE_ID.getId(), probeIdCaptor.getAllValues().get(0).getId()); assertEquals( - "Instrumentation failed for CapturedSnapshot01: java.lang.RuntimeException: Method Parameters attribute detected, instrumentation not supported", + "Instrumentation failed for CapturedSnapshot01: Method Parameters attribute detected, instrumentation not supported", strCaptor.getAllValues().get(0)); } else { Snapshot snapshot = assertOneSnapshot(listener); @@ -3069,9 +3069,17 @@ public void methodParametersAttribute() throws Exception { @Test @EnabledForJreRange(min = JRE.JAVA_17) - public void methodParametersAttributeRecord() throws IOException, URISyntaxException { + public void methodParametersAttributeRecord() throws Exception { final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot29"; final String RECORD_NAME = "com.datadog.debugger.MyRecord1"; + Config config = mock(Config.class); + when(config.isDebuggerCodeOriginEnabled()).thenReturn(false); + when(config.isDebuggerExceptionEnabled()).thenReturn(false); + when(config.isDynamicInstrumentationEnabled()).thenReturn(false); + Instrumentation inst = mock(Instrumentation.class); + Class springClass = Class.forName("org.springframework.core.SpringVersion"); + when(inst.getAllLoadedClasses()).thenReturn(new Class[] {springClass}); + DebuggerAgent.run(config, inst, null); TestSnapshotListener listener = installMethodProbeAtExit(RECORD_NAME, "", null); Map buffers = compile(CLASS_NAME, SourceCompiler.DebugInfo.ALL, "17", Arrays.asList("-parameters")); @@ -3089,7 +3097,7 @@ public void methodParametersAttributeRecord() throws IOException, URISyntaxExcep verify(probeStatusSink, times(1)).addError(probeIdCaptor.capture(), strCaptor.capture()); assertEquals(PROBE_ID.getId(), probeIdCaptor.getAllValues().get(0).getId()); assertEquals( - "Instrumentation failed for com.datadog.debugger.MyRecord1: java.lang.RuntimeException: Method Parameters attribute detected, instrumentation not supported", + "Instrumentation failed for com.datadog.debugger.MyRecord1: Method Parameters attribute detected, instrumentation not supported", strCaptor.getAllValues().get(0)); } }