Skip to content

Commit c721c5b

Browse files
authored
Don't reference ThreadDeath directly due to its future removal (#2879)
1 parent c5fff07 commit c721c5b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/io/vavr/control/Try.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ interface TryModule {
18481848
static boolean isFatal(Throwable throwable) {
18491849
return throwable instanceof InterruptedException
18501850
|| throwable instanceof LinkageError
1851-
|| throwable instanceof ThreadDeath
1851+
|| ThreadDeathChecker.isThreadDeath(throwable)
18521852
|| throwable instanceof VirtualMachineError;
18531853
}
18541854

@@ -1858,4 +1858,19 @@ static <T extends Throwable, R> R sneakyThrow(Throwable t) throws T {
18581858
throw (T) t;
18591859
}
18601860

1861+
class ThreadDeathChecker {
1862+
static final Class<?> THREAD_DEATH_CLASS = resolve();
1863+
1864+
static boolean isThreadDeath(Throwable throwable) {
1865+
return THREAD_DEATH_CLASS != null && THREAD_DEATH_CLASS.isInstance(throwable);
1866+
}
1867+
1868+
private static Class<?> resolve() {
1869+
try {
1870+
return Class.forName("java.lang.ThreadDeath");
1871+
} catch (ClassNotFoundException e) {
1872+
return null;
1873+
}
1874+
}
1875+
}
18611876
}

0 commit comments

Comments
 (0)