Skip to content

Commit 3ce61b1

Browse files
authored
Don't reference ThreadDeath directly due to its future removal (#2878)
`ThreadDeath` is deprecated for removal, so we can no longer reference it directly.
1 parent 7fcf56d commit 3ce61b1

File tree

1 file changed

+18
-1
lines changed
  • vavr/src/main/java/io/vavr/control

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ interface TryModule {
16961696
static boolean isFatal(Throwable throwable) {
16971697
return throwable instanceof InterruptedException
16981698
|| throwable instanceof LinkageError
1699-
|| throwable instanceof ThreadDeath
1699+
|| ThreadDeathResolver.isThreadDeath(throwable)
17001700
|| throwable instanceof VirtualMachineError;
17011701
}
17021702

@@ -1706,4 +1706,21 @@ static <T extends Throwable, R> R sneakyThrow(Throwable t) throws T {
17061706
throw (T) t;
17071707
}
17081708

1709+
static class ThreadDeathResolver {
1710+
static final Class<?> THREAD_DEATH_CLASS = resolve();
1711+
1712+
static boolean isThreadDeath(Throwable throwable) {
1713+
return THREAD_DEATH_CLASS != null && THREAD_DEATH_CLASS.isInstance(throwable);
1714+
}
1715+
1716+
private static Class<?> resolve() {
1717+
try {
1718+
return Class.forName("java.lang.ThreadDeath");
1719+
} catch (ClassNotFoundException e) {
1720+
return null;
1721+
}
1722+
}
1723+
}
17091724
}
1725+
1726+

0 commit comments

Comments
 (0)