Skip to content

Commit

Permalink
Support JDK 21 in ThreadUtilsTest.smoke
Browse files Browse the repository at this point in the history
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.

PiperOrigin-RevId: 506393875
Change-Id: I653cbded4e80181348c4cd1d379cb58fdbf8f55d
  • Loading branch information
anakanemison authored and copybara-github committed Feb 1, 2023
1 parent e5b8090 commit 7e43627
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ public void handleCrash(Crash crash, CrashContext ctx) {
.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();
Expand Down

0 comments on commit 7e43627

Please sign in to comment.