Another Thread.stop() issue

Dalibor Topic robilad at yahoo.com
Wed May 31 03:29:34 PDT 2000


Hi,

I've got a bit of follow-up on Jason's Thread.stop() message. I've found a
bug in Kaffe's Thread.stop(Thowable object) method. The following code, legal
under Java 1.1, 1.2 and 1.3 exposes it:

---ThreadStop.java---
class Runner extends Thread {

    public void run() {
	try{
	    //Sleep for a while
	    sleep(10000);
	}
	catch (InterruptedException _) {}

    }
}

class ThreadStop {
    static public void main(String[] argv) {

	Runner u = new Runner();

	// start runner thread

	u.start();

	try {
	    Thread.currentThread().sleep(1000);
	}
	catch (InterruptedException e) {
	    e.printStackTrace();
	}

	u.stop(new Exception("Success."));

	try {
	    Thread.currentThread().sleep(1000);
	}
	catch (InterruptedException e) {
	    e.printStackTrace();
	}

	System.exit(0);
    }
}
---cut!---
r
unning it with JDK 1.1.7 on Linux gives me:
$ java ThreadStop 
java.lang.Exception: Success.

running it with lates kaffe from CVS gives me:
$ kaffe ThreadStop 
java.lang.ClassCastException: can't cast `java/lang/Exception' to `java/lang/Error'
        at java.lang.Thread.waitOn(Thread.java:473)
        at java.lang.Thread.sleep(Thread.java:364)
        at Runner.run(ThreadStop.java:7)

If you take a look at the code, you'll see death being cast  to an Error
object, which can be thrown without requiring special declaration. On the other
hand, the stop(Throwable) method can receive any kind of throwable object, so
it seems to be a bug to cast it to an Error. 

I tried to fix the this with some obvoiues fixes (remove death altogether,
allways use stop0) but unfortunately I couldn't get it to work. I kept getting
this:

java.lang.IllegalMonitorStateException
        at java.lang.Thread.sleep(Thread.java:364)
        at Runner.run(ThreadStop.java:23)

So I decided to leave it up to the great threading hackers to fix the things :)

Have some fun,
Dali

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com



More information about the kaffe mailing list