NullPointerException in waitCond()

Archie Cobbs archie at whistle.com
Thu Jul 30 13:34:14 PDT 1998


I wrote:
> Wait 0x634038 lk=0x0 from getLock()
> java.lang.NullPointerException
>         at java/lang/Object.wait(46)
>         at java/lang/Object.wait(42)
> 	...
> 
> The NULL return from getLock() is causing the problem (because
> the first thing __waitCond() does is dereference it).

Hmm.. on further examination, it looks like my code was trying
to wait() on an object for which it didn't hold the lock, and therefore
kaffe should have thrown an IllegalMonitorStateException...

The patch below fixes the problem (at least in my case).

-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com

Index: kaffe/kaffevm/locks.c
===================================================================
RCS file: /cvs/mod/net/kaffe/kaffe/kaffevm/locks.c,v
retrieving revision 1.1.1.3
diff -c -u -r1.1.1.3 locks.c
--- locks.c	1998/07/14 16:48:42	1.1.1.3
+++ locks.c	1998/07/30 20:32:17
@@ -231,7 +231,7 @@
 {
 DBG(VMCONDS,	dprintf("Wait 0x%x on iLock=0x%x\n", THREAD_NATIVE(), lk);	)
 
-	if (lk->holder != (*Kaffe_ThreadInterface.currentNative)()) {
+	if (lk == 0 || lk->holder != (*Kaffe_ThreadInterface.currentNative)()) {
 		throwException(IllegalMonitorStateException);
 	}
 
@@ -268,7 +268,7 @@
 {
 DBG(VMCONDS,	dprintf("Signal 0x%x on iLock=0x%x\n", THREAD_NATIVE(), lk);)
 
-	if (lk->holder != (*Kaffe_ThreadInterface.currentNative)()) {
+	if (lk == 0 || lk->holder != (*Kaffe_ThreadInterface.currentNative)()) {
 		throwException(IllegalMonitorStateException);
 	}
 
@@ -302,7 +302,7 @@
 {
 DBG(VMCONDS,	dprintf("Broadcast 0x%x on iLock=0x%x\n", THREAD_NATIVE(), lk);)
 
-	if (lk->holder != (*Kaffe_ThreadInterface.currentNative)()) {
+	if (lk == 0 || lk->holder != (*Kaffe_ThreadInterface.currentNative)()) {
 		throwException(IllegalMonitorStateException);
 	}
 


More information about the kaffe mailing list