...
According to the Java API [API 2014], class Thread
:
[
Thread.stop()
] This method was originally designed to force a thread to stop and throw a givenThrowable
as an exception. It was inherently unsafe (seeThread.stop()
for details), and furthermore could be used to generate exceptions that the target thread was not prepared to handle.
...
For example, the following method is behaviorally identical to Java's throw operation , but circumvents the compiler's attempts to guarantee that the calling method has declared all of the checked exceptions that it may throw.
Code Block | ||
---|---|---|
| ||
static void sneakyThrow(Throwable t) { Thread.currentThread().stop(t); } |
Note that the Thread.stop()
methods are deprecated, so this code also violates MET02-J. Do not use deprecated or obsolete classes or methods.
...
It is also possible to disassemble a class, remove any declared checked exceptions, and reassemble the class so that checked exceptions are thrown at runtime when the class is used [Roubtsov 2003]. Compiling against a class that declares the checked exception and supplying at runtime a class that lacks the declaration can also result in undeclared checked exceptions. Undeclared checked exceptions can also be produced through crafted use of the sun.corba.Bridge
class. All of these practices are violations of this rule.
...
Bibliography
[API 2014] | Thread.stop(Throwable) |
Item 2, "Consider a Builder When Faced with Many Constructor Parameters" | |
| |
[JLS 2015] | |
| |
| |
"Scalability of Checked Exceptions" |
...