[concurrency-interest] Thread interruption protocol: InterruptedException is a "checked" exception, correct?

Tom Hawtin Thomas.Hawtin at Sun.COM
Wed May 20 10:11:19 EDT 2009


Péter Kovács wrote:
> Is it possible to get java.lang.InterruptedException, even if none of
> the method along the call stack declares this exception?
> 
> We are experiencing such a case. Class.forName(String) appears to
> throw the exception.

Class.newInstance is more likely to be the culprit:

"Note that this method propagates any exception thrown by the nullary 
constructor, including a checked exception. Use of this method 
effectively bypasses the compile-time exception checking that would 
otherwise be performed by the compiler. The Constructor.newInstance 
method avoids this problem by wrapping any exception thrown by the 
constructor in a (checked) InvocationTargetException."

http://java.sun.com/javase/6/docs/api/java/lang/Class.html#newInstance()

The same thing can be done with Thread.stop(Throwable), unchecked casts 
and playing silly buggers with bytecode

> Is it not a breach of one of the fundamental contracts of the Java
> language: "checked" exception are not allowed to be thrown in a method
> without this method being declared to (potentially) throw it? (We
> catch this exception as a Throwable in a catch(Throwable) clause.)

Of the language yes (with exception for unsafe casts); of the VM no.

Tom Hawtin


More information about the Concurrency-interest mailing list