Skip to content

Commit 6ae1a5c

Browse files
authored
fix debugger test for stable JVM (#9233)
Since JDK 24, lambdas are renumbered from the local scope and not from the whole classfile
1 parent 2bf5e75 commit 6ae1a5c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SymbolExtractionTransformerTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.junit.jupiter.api.Assertions.assertEquals;
66
import static org.junit.jupiter.api.Assertions.assertFalse;
77
import static org.junit.jupiter.api.Assertions.assertNull;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
89
import static org.mockito.Mockito.when;
910
import static utils.InstrumentationTestHelper.compileAndLoadClass;
1011

@@ -521,7 +522,7 @@ public void symbolExtraction09() throws IOException, URISyntaxException {
521522
19);
522523
Scope supplierClosureScope = classScope.getScopes().get(3);
523524
assertScope(
524-
supplierClosureScope, ScopeType.CLOSURE, "lambda$process$1", 20, 21, SOURCE_FILE, 1, 0);
525+
supplierClosureScope, ScopeType.CLOSURE, "lambda$process$*", 20, 21, SOURCE_FILE, 1, 0);
525526
Scope supplierClosureLocalScope = supplierClosureScope.getScopes().get(0);
526527
assertScope(supplierClosureLocalScope, ScopeType.LOCAL, null, 20, 21, SOURCE_FILE, 0, 1);
527528
assertSymbol(
@@ -676,7 +677,7 @@ public void symbolExtraction12() throws IOException, URISyntaxException {
676677
fooMethodScope.getSymbols().get(0), SymbolType.ARG, "arg", Integer.TYPE.getTypeName(), 17);
677678
Scope lambdaFoo3MethodScope = classScope.getScopes().get(3);
678679
assertScope(
679-
lambdaFoo3MethodScope, ScopeType.CLOSURE, "lambda$foo$3", 19, 19, SOURCE_FILE, 0, 1);
680+
lambdaFoo3MethodScope, ScopeType.CLOSURE, "lambda$foo$*", 19, 19, SOURCE_FILE, 0, 1);
680681
assertSymbol(
681682
lambdaFoo3MethodScope.getSymbols().get(0),
682683
SymbolType.ARG,
@@ -685,7 +686,7 @@ public void symbolExtraction12() throws IOException, URISyntaxException {
685686
19);
686687
Scope lambdaFoo2MethodScope = classScope.getScopes().get(4);
687688
assertScope(
688-
lambdaFoo2MethodScope, ScopeType.CLOSURE, "lambda$foo$2", 19, 19, SOURCE_FILE, 0, 1);
689+
lambdaFoo2MethodScope, ScopeType.CLOSURE, "lambda$foo$*", 19, 19, SOURCE_FILE, 0, 1);
689690
assertSymbol(
690691
lambdaFoo2MethodScope.getSymbols().get(0),
691692
SymbolType.ARG,
@@ -856,7 +857,7 @@ public void symbolExtraction14() throws IOException, URISyntaxException {
856857
}
857858

858859
@Test
859-
@EnabledOnJre({JRE.JAVA_17, JRE.JAVA_21})
860+
@EnabledOnJre({JRE.JAVA_17, JRE.JAVA_21, JRE.JAVA_24})
860861
@DisabledIf(
861862
value = "datadog.environment.JavaVirtualMachine#isJ9",
862863
disabledReason = "Flaky on J9 JVMs")
@@ -991,7 +992,12 @@ private static void assertScope(
991992
int nbScopes,
992993
int nbSymbols) {
993994
assertEquals(scopeType, scope.getScopeType());
994-
assertEquals(name, scope.getName());
995+
if (name != null && name.endsWith("*")) {
996+
name = name.substring(0, name.length() - 1);
997+
assertTrue(scope.getName().startsWith(name));
998+
} else {
999+
assertEquals(name, scope.getName());
1000+
}
9951001
assertEquals(startLine, scope.getStartLine());
9961002
assertEquals(endLine, scope.getEndLine());
9971003
assertEquals(sourceFile, scope.getSourceFile());

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/util/ClassFileLinesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ void getMethodsByLineWithLambdas() throws Exception {
7171
assertEquals("multiLambda", methods58.get(0).name);
7272
assertEquals("(Ljava/lang/String;)I", methods58.get(0).desc);
7373
// filter
74-
assertEquals("lambda$multiLambda$3", methods58.get(1).name);
74+
assertTrue(methods58.get(1).name.startsWith("lambda$multiLambda$"));
7575
assertEquals("(Ljava/lang/String;)Z", methods58.get(1).desc);
7676
// map
77-
assertEquals("lambda$multiLambda$2", methods58.get(2).name);
77+
assertTrue(methods58.get(2).name.startsWith("lambda$multiLambda$"));
7878
assertEquals("(Ljava/lang/String;)Ljava/lang/String;", methods58.get(2).desc);
7979
}
8080

0 commit comments

Comments
 (0)