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 @@ -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;
}
Expand Down Expand Up @@ -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<ProbeDefinition> 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
Expand All @@ -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;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,11 @@ public void addDiagnostics(ProbeId probeId, List<DiagnosticMessage> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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, "<init>", null);
Map<String, byte[]> buffers =
compile(CLASS_NAME, SourceCompiler.DebugInfo.ALL, "17", Arrays.asList("-parameters"));
Expand All @@ -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));
}
}
Expand Down
Loading