Skip to content

Commit 6a9203c

Browse files
authored
Fix structured concurrency test on jdk 25 (#13936)
1 parent c36eedd commit 6a9203c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

instrumentation/executors/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeInstrumentation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.javaagent.instrumentation.executors;
77

88
import static net.bytebuddy.matcher.ElementMatchers.named;
9+
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
910
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
1011

1112
import io.opentelemetry.context.Context;
@@ -24,7 +25,10 @@ public class StructuredTaskScopeInstrumentation implements TypeInstrumentation {
2425

2526
@Override
2627
public ElementMatcher<TypeDescription> typeMatcher() {
27-
return named("java.util.concurrent.StructuredTaskScope");
28+
return namedOneOf(
29+
"java.util.concurrent.StructuredTaskScope",
30+
// since jdk 25-ea+24
31+
"java.util.concurrent.StructuredTaskScopeImpl");
2832
}
2933

3034
@Override

instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/StructuredTaskScopeTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,24 @@ class StructuredTaskScopeTest {
2121
@RegisterExtension
2222
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
2323

24+
@SuppressWarnings({
25+
"unchecked",
26+
"rawtypes"
27+
}) // type arguments for StructuredTaskScope change between jdk 21 and 25
2428
@Test
2529
void multipleForkJoin() throws Exception {
26-
StructuredTaskScope<Object> taskScope = new StructuredTaskScope.ShutdownOnFailure();
30+
StructuredTaskScope tmp;
31+
try {
32+
// since jdk 25-ea+24
33+
tmp = (StructuredTaskScope) StructuredTaskScope.class.getMethod("open").invoke(null);
34+
} catch (NoSuchMethodException exception) {
35+
tmp =
36+
Class.forName("java.util.concurrent.StructuredTaskScope$ShutdownOnFailure")
37+
.asSubclass(StructuredTaskScope.class)
38+
.getConstructor()
39+
.newInstance();
40+
}
41+
StructuredTaskScope taskScope = tmp;
2742

2843
Callable<String> callable1 =
2944
() -> {

0 commit comments

Comments
 (0)