Skip to content

Commit 63e8a26

Browse files
jpbempeldevflow.devflow-routing-intake
andauthored
Update record detection for fixed JDK (#12031)
Update record detection for fixed JDK JDK 25.0.4 fixes the Record with type annotation bug (JDK-8376185) so we are updating the detection to filter out for this JDK version and onward Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 7671c23 commit 63e8a26

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class ConfigurationUpdater implements DebuggerContext.ProbeResolver, Conf
5757
private static final int MINUTES_BETWEEN_ERROR_LOG = 5;
5858
private static final boolean JAVA_AT_LEAST_19 = JavaVirtualMachine.isJavaVersionAtLeast(19);
5959
private static final boolean JAVA_AT_LEAST_16 = JavaVirtualMachine.isJavaVersionAtLeast(16);
60+
private static final boolean JAVA_AT_LEAST_25_0_4 =
61+
JavaVirtualMachine.isJavaVersionAtLeast(25, 0, 4);
6062
private static final Method GET_RECORD_COMPONENTS_METHOD;
6163
private static final Method GET_ANNOTATED_TYPES_METHOD;
6264

@@ -353,8 +355,9 @@ private static class JDKVersionSpecificHelper {
353355

354356
public static List<Class<?>> detectRecordWithTypeAnnotation(
355357
Consumer<String> reportError, List<Class<?>> changedClasses) {
356-
if (!JAVA_AT_LEAST_16) {
358+
if (!JAVA_AT_LEAST_16 || JAVA_AT_LEAST_25_0_4) {
357359
// records introduced in JDK 16 (final version)
360+
// JDK-8376185 fixed since JDK 25.0.4
358361
return changedClasses;
359362
}
360363
List<Class<?>> result = new ArrayList<>();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public class DebuggerTransformer implements ClassFileTransformer {
9595
SpanProbe.class);
9696
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";
9797
private static final boolean JAVA_AT_LEAST_19 = JavaVirtualMachine.isJavaVersionAtLeast(19);
98+
private static final boolean JAVA_AT_LEAST_25_0_4 =
99+
JavaVirtualMachine.isJavaVersionAtLeast(25, 0, 4);
98100
public static Path DUMP_PATH = Paths.get(SystemProperties.get(JAVA_IO_TMPDIR), "debugger");
99101
private static final String[] SKIPPED_PACKAGES =
100102
new String[] {
@@ -353,6 +355,9 @@ private boolean checkMethodParameters(
353355
*/
354356
private boolean checkRecordTypeAnnotation(
355357
ClassNode classNode, List<ProbeDefinition> definitions, String fullyQualifiedClassName) {
358+
if (JAVA_AT_LEAST_25_0_4) {
359+
return true;
360+
}
356361
if (!ASMHelper.isRecord(classNode)) {
357362
return true;
358363
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,10 @@ public void noInstrumentationForAgentClasses() throws Exception {
32833283
@Test
32843284
@EnabledForJreRange(min = JRE.JAVA_17)
32853285
public void recordWithTypeAnnotation() throws IOException, URISyntaxException {
3286+
if (JavaVirtualMachine.isJavaVersionAtLeast(25, 0, 4)) {
3287+
// Fixed since JDK 25.0.4
3288+
return;
3289+
}
32863290
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot33";
32873291
LogProbe probe1 = createMethodProbeAtExit(PROBE_ID1, CLASS_NAME, "parse", null);
32883292
TestSnapshotListener listener = installProbes(probe1);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,10 @@ public void methodParametersAttributeRecord()
715715
@EnabledForJreRange(min = JRE.JAVA_17)
716716
public void recordWithTypeAnnotation()
717717
throws IOException, URISyntaxException, UnmodifiableClassException {
718-
// make sure record method are not detected as having methodParameters attribute.
719-
// /!\ record canonical constructor has the MethodParameters attribute,
720-
// but not returned by Class::getDeclaredMethods()
718+
if (JavaVirtualMachine.isJavaVersionAtLeast(25, 0, 4)) {
719+
// Fixed since JDK 25.0.4
720+
return;
721+
}
721722
final String CLASS_NAME = "com.datadog.debugger.CapturedSnapshot33";
722723
Map<String, byte[]> buffers = compile(CLASS_NAME, SourceCompiler.DebugInfo.ALL, "17");
723724
Class<?> testClass = loadClass(CLASS_NAME, buffers);

0 commit comments

Comments
 (0)