Time to put a stop to Thread.stop?

Alan Bateman Alan.Bateman at oracle.com
Wed Oct 9 11:00:59 UTC 2013

On 09/10/2013 08:47, Dr Heinz M. Kabutz wrote:
> I noticed the other day when using Java 8 that Thread.stop(Throwable) 
> was throwing an UOE.  Unfortunately I missed the discussion in May 
> amongst the thousands of other important JDK emails.  Thus I presume 
> that nothing I might have to say on the matter would change what is 
> currently in the OpenJDK ;-)  But I'd like to state it "for the 
> record" anyway.
> Throwing checked exceptions in an unchecked context is, IMHO, 
> something one should almost never do, except maybe in test cases.  Up 
> to now, I've known of quite a few ways to do this though:
> 1. Thread.stop(Throwable) with some mangling - see ThrowerConcurrent 
> in http://www.javaspecialists.eu/archive/Issue144.html
> 2. Abusing generics
> 3. Class.newInstance(), described in Java Puzzlers 
> (http://www.javaspecialists.eu/archive/Issue144.html)
> 4. Unsafe.throwException() similar to ThrowerConcurrent in #1.
> Since this is something that we should not do anyway, it is no harm to 
> remove one of the ways, this being Thread.stop(Throwable).
As I'm sure you can appreciate, it consumes a lot of oxygen to remove 
something and I'm hoping we don't have to spend any more time on this 
one. One comment on your list is that #1 differs in that it can cause 
other threads to misbehave and this is one of the main motives for 
finally pulling the plug on this method. For a sneakyThrow on the 
current thread then there are other options (as your puzzlers 
demonstrate) but hopefully there aren't too many cases where non-test 
code needs to do this.


More information about the core-libs-dev mailing list