Skip to content

Commit

Permalink
Don't reference ThreadDeath directly due to its future removal
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit committed Oct 3, 2024
1 parent 7fcf56d commit d796e54
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion vavr/src/main/java/io/vavr/control/Try.java
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ interface TryModule {
static boolean isFatal(Throwable throwable) {
return throwable instanceof InterruptedException
|| throwable instanceof LinkageError
|| throwable instanceof ThreadDeath
|| ThreadDeathResolver.isThreadDeath(throwable)
|| throwable instanceof VirtualMachineError;
}

Expand All @@ -1707,3 +1707,19 @@ static <T extends Throwable, R> R sneakyThrow(Throwable t) throws T {
}

}

static class ThreadDeathResolver {
static final Class<?> THREAD_DEATH_CLASS = resolve();

static boolean isThreadDeath(Throwable throwable) {
return THREAD_DEATH_CLASS != null && THREAD_DEATH_CLASS.isInstance(throwable);
}

private static Class<?> resolve() {
try {
return Class.forName("java.lang.ThreadDeath");
} catch (ClassNotFoundException e) {
return null;
}
}
}

0 comments on commit d796e54

Please sign in to comment.