Skip to content

Commit

Permalink
Don't reference ThreadDeath directly due to its future removal (#2878)
Browse files Browse the repository at this point in the history
`ThreadDeath` is deprecated for removal, so we can no longer reference it directly.
  • Loading branch information
pivovarit authored Oct 3, 2024
1 parent 7fcf56d commit 3ce61b1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 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 @@ -1706,4 +1706,21 @@ static <T extends Throwable, R> R sneakyThrow(Throwable t) throws T {
throw (T) 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 3ce61b1

Please sign in to comment.