Support JDK 21 in ThreadUtilsTest.smoke
In JDK 21, Thread.sleep calls a "sleep0" native method. This CL fixes the
test's stack trace expectations by making it tolerant of either JDK's
stack.
@@ -74,10 +74,17 @@ public class ThreadUtilsTest {
.hasCauseThat()
.hasMessageThat()
.isEqualTo("(Wrapper exception for longest stack trace) interrupt message");
- assertThat(reportedException.get().getCause().getStackTrace()[0].getMethodName())
- .isEqualTo("sleep");
- assertThat(reportedException.get().getCause().getStackTrace()[1].getMethodName())
- .isEqualTo("recursiveMethodNoPark");
+ // The topmost method is either "sleep" or "sleep0". For example, in JDK 21, "Thread.sleep"
+ // calls a "sleep0" native method.
+ StackTraceElement[] stackTrace = reportedException.get().getCause().getStackTrace();
+ if (stackTrace[0].getMethodName().equals("sleep0")) {
+ assertThat(stackTrace[1].getMethodName()).isEqualTo("sleep");
+ assertThat(stackTrace[2].getMethodName()).isEqualTo("recursiveMethodNoPark");
+ } else {
+ assertThat(stackTrace[0].getMethodName()).isEqualTo("sleep");
+ assertThat(stackTrace[1].getMethodName()).isEqualTo("recursiveMethodNoPark");
+ }
+
future.set(1);
for (Thread thread : parkThreads) {
thread.join();
