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

Péter Kovács peter.kovacs.1.0rc at gmail.com
Wed May 20 11:15:22 EDT 2009


Tom,

I highly appreciate your input.

The doc you quoted says that the original exception is wrapped in an
InvocationTargetException instance. Similarly, I'd expect that if an
exception occurs during Class loading, it is wrapped in an
ExceptionInInitializerError, correct?

What we're seeing in our case is a plain InterruptedException:

...
Caused by: java.lang.InterruptedException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
...

Thanks
Peter

2009/5/20 Tom Hawtin <Thomas.Hawtin at sun.com>:
> 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