Skip to content

Commit 0bf04c1

Browse files
jpbempeldevflow.devflow-routing-intake
andauthored
Update MethodParameters detection for fixed JDK (#12025)
Update MethodParameters detection for fixed JDK JDK 17.0.20 fixes the Method Parameters bug (JDK-8240908) so we are updating the detection to filter out for this JDK version and onward # Conflicts: # dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java fix tests to exact patch version remove unnecessary JDK19 checks Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent ac42cd4 commit 0bf04c1

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/ConfigurationUpdater.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
public class ConfigurationUpdater implements DebuggerContext.ProbeResolver, ConfigurationAcceptor {
5656
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationUpdater.class);
5757
private static final int MINUTES_BETWEEN_ERROR_LOG = 5;
58-
private static final boolean JAVA_AT_LEAST_19 = JavaVirtualMachine.isJavaVersionAtLeast(19);
58+
private static final boolean JAVA_AT_LEAST_17_0_20 =
59+
JavaVirtualMachine.isJavaVersionAtLeast(17, 0, 20);
5960
private static final boolean JAVA_AT_LEAST_16 = JavaVirtualMachine.isJavaVersionAtLeast(16);
6061
private static final boolean JAVA_AT_LEAST_25_0_4 =
6162
JavaVirtualMachine.isJavaVersionAtLeast(25, 0, 4);
@@ -423,8 +424,8 @@ public static List<Class<?>> detectMethodParameters(
423424
Consumer<String> reportError,
424425
Instrumentation instrumentation,
425426
List<Class<?>> changedClasses) {
426-
if (JAVA_AT_LEAST_19) {
427-
// bug is fixed since JDK19, no need to perform detection
427+
if (JAVA_AT_LEAST_17_0_20) {
428+
// bug is fixed since JDK 19 and 17.0.20, no need to perform detection
428429
return changedClasses;
429430
}
430431
List<Class<?>> result = new ArrayList<>();

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ public class DebuggerTransformer implements ClassFileTransformer {
9494
SpanDecorationProbe.class,
9595
SpanProbe.class);
9696
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
97-
private static final boolean JAVA_AT_LEAST_19 = JavaVirtualMachine.isJavaVersionAtLeast(19);
9897
private static final boolean JAVA_AT_LEAST_25_0_4 =
9998
JavaVirtualMachine.isJavaVersionAtLeast(25, 0, 4);
99+
private static final boolean JAVA_AT_LEAST_17_0_20 =
100+
JavaVirtualMachine.isJavaVersionAtLeast(17, 0, 20);
100101
public static Path DUMP_PATH = Paths.get(SystemProperties.get(JAVA_IO_TMPDIR), "debugger");
101102
private static final String[] SKIPPED_PACKAGES =
102103
new String[] {
@@ -311,8 +312,8 @@ public byte[] transform(
311312
*/
312313
private boolean checkMethodParameters(
313314
ClassNode classNode, List<ProbeDefinition> definitions, String fullyQualifiedClassName) {
314-
if (JAVA_AT_LEAST_19) {
315-
// bug is fixed since JDK19, no need to perform check
315+
if (JAVA_AT_LEAST_17_0_20) {
316+
// bug is fixed since JDK 19 and 17.0.20, no need to perform check
316317
return true;
317318
}
318319
boolean isRecord = ASMHelper.isRecord(classNode);

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,7 +3191,7 @@ public void methodParametersAttribute() throws Exception {
31913191
Class<?> testClass = loadClass(CLASS_NAME, buffers);
31923192
int result = Reflect.onClass(testClass).call("main", "1").get();
31933193
assertEquals(3, result);
3194-
if (JavaVirtualMachine.isJavaVersion(17)) {
3194+
if (JavaVirtualMachine.isJavaVersionBetween(17, 0, 0, 17, 0, 20)) {
31953195
// on JDK 17 with Spring6 class, transformation cannot happen
31963196
assertEquals(0, listener.snapshots.size());
31973197
ArgumentCaptor<ProbeId> probeIdCaptor = ArgumentCaptor.forClass(ProbeId.class);
@@ -3226,7 +3226,8 @@ public void methodParametersAttributeRecord() throws Exception {
32263226
Class<?> testClass = loadClass(CLASS_NAME, buffers);
32273227
int result = Reflect.onClass(testClass).call("main", "1").get();
32283228
assertEquals(42, result);
3229-
if (JavaVirtualMachine.isJavaVersionAtLeast(19)) {
3229+
if (JavaVirtualMachine.isJavaVersionAtLeast(19)
3230+
|| JavaVirtualMachine.isJavaVersionAtLeast(17, 0, 20)) {
32303231
Snapshot snapshot = assertOneSnapshot(listener);
32313232
assertCaptureArgs(
32323233
snapshot.getCaptures().getReturn(), "firstName", String.class.getTypeName(), "john");

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/ConfigurationUpdaterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ public void methodParametersAttribute() throws Exception {
658658
Map<String, byte[]> buffers =
659659
compile(CLASS_NAME, SourceCompiler.DebugInfo.ALL, "8", Arrays.asList("-parameters"));
660660
Class<?> testClass = loadClass(CLASS_NAME, buffers);
661-
if (JavaVirtualMachine.isJavaVersion(17)) {
661+
if (JavaVirtualMachine.isJavaVersionBetween(17, 0, 0, 17, 0, 20)) {
662662
// on JDK 17 introduced Spring6 class
663663
Class<?> springClass = Class.forName("org.springframework.core.SpringVersion");
664664
when(inst.getAllLoadedClasses()).thenReturn(new Class[] {testClass, springClass});
@@ -669,7 +669,7 @@ public void methodParametersAttribute() throws Exception {
669669
configurationUpdater.accept(
670670
REMOTE_CONFIG,
671671
singletonList(LogProbe.builder().probeId(PROBE_ID).where(CLASS_NAME, "main").build()));
672-
if (JavaVirtualMachine.isJavaVersion(17)) {
672+
if (JavaVirtualMachine.isJavaVersionBetween(17, 0, 0, 17, 0, 20)) {
673673
// on JDK 17 with Spring6 class, transformation cannot happen
674674
verify(inst, times(2)).getAllLoadedClasses();
675675
verify(inst, times(0)).retransformClasses(any());

0 commit comments

Comments
 (0)