Hi,

I was hunting down a ArrayStoreException and was missing a message
telling what exactly went wrong. The following patch adds a message
wherever an ArrayStoreException is thrown in the vm or native code.

2004-11-13  Mark Wielaard  <[EMAIL PROTECTED]>

        * include/errors.h
        (ArrayStoreException): Define to take a message.
        * kaffe/kaffevm/soft.c
        (soft_checkarraystore): Add message to ArrayStoreException.
        * libraries/clib/native/System.c
        (java_lang_System_arraycopy): Likewise.

Hope this is useful for others.

Cheers,

Mark
Index: include/errors.h
===================================================================
RCS file: /cvs/kaffe/kaffe/include/errors.h,v
retrieving revision 1.14
diff -u -r1.14 errors.h
--- include/errors.h	31 Oct 2004 14:35:32 -0000	1.14
+++ include/errors.h	13 Nov 2004 20:43:45 -0000
@@ -101,7 +101,7 @@
 #define IllegalMonitorStateException NEW_LANG_EXCEPTION(IllegalMonitorStateException)
 #define NullPointerException NEW_LANG_EXCEPTION(NullPointerException)
 #define ArrayIndexOutOfBoundsException NEW_LANG_EXCEPTION(ArrayIndexOutOfBoundsException)
-#define ArrayStoreException NEW_LANG_EXCEPTION(ArrayStoreException)
+#define ArrayStoreException(M) NEW_LANG_EXCEPTION_MESSAGE(ArrayStoreException, M)
 #define ArithmeticException NEW_LANG_EXCEPTION(ArithmeticException)
 #define AbstractMethodError(M) NEW_LANG_EXCEPTION_MESSAGE(AbstractMethodError, M)
 #define ThreadDeath NEW_LANG_EXCEPTION(ThreadDeath)
Index: kaffe/kaffevm/soft.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/soft.c,v
retrieving revision 1.67
diff -u -r1.67 soft.c
--- kaffe/kaffevm/soft.c	6 Nov 2004 20:02:07 -0000	1.67
+++ kaffe/kaffevm/soft.c	13 Nov 2004 20:43:45 -0000
@@ -584,7 +584,16 @@
 soft_checkarraystore(Hjava_lang_Object* array, Hjava_lang_Object* obj)
 {
 	if (obj != 0 && soft_instanceof(CLASS_ELEMENT_TYPE(OBJECT_CLASS(array)), obj) == 0) {
-		throwException(ArrayStoreException);
+		Hjava_lang_Throwable* asexc;
+		const char* f = "can't store `%s' in `%s'";
+		const char *otype = CLASS_CNAME(OBJECT_CLASS(obj));
+		const char *atype = CLASS_CNAME(OBJECT_CLASS(array));
+		char *b;
+		b = checkPtr(KMALLOC(strlen(otype)+strlen(atype)+strlen(f)));
+		sprintf(b, f, otype, atype);
+		asexc = ArrayStoreException(b);
+		KFREE(b);
+		throwException(asexc);
 	}
 }
 
Index: libraries/clib/native/System.c
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/clib/native/System.c,v
retrieving revision 1.59
diff -u -r1.59 System.c
--- libraries/clib/native/System.c	14 Oct 2004 11:12:10 -0000	1.59
+++ libraries/clib/native/System.c	13 Nov 2004 20:43:48 -0000
@@ -519,8 +519,28 @@
 	dclass = OBJECT_CLASS(dst);
 
 	/* Must be arrays */ 	 
-	if (!CLASS_IS_ARRAY(sclass) || !CLASS_IS_ARRAY(dclass)) { 	 
-		throwException (ArrayStoreException);
+	if (!CLASS_IS_ARRAY(sclass)) {
+		Hjava_lang_Throwable* asexc;
+		const char* f = "source not an array `%s'";
+		const char *type = CLASS_CNAME(sclass);
+		char *b;
+		b = checkPtr(KMALLOC(strlen(type)+strlen(f)));
+		sprintf(b, f, type);
+		asexc = ArrayStoreException(b);
+		KFREE(b);
+		throwException(asexc);
+	}
+
+	if(!CLASS_IS_ARRAY(dclass)) { 	 
+		Hjava_lang_Throwable* asexc;
+		const char* f = "destination not an array `%s'";
+		const char *type = CLASS_CNAME(dclass);
+		char *b;
+		b = checkPtr(KMALLOC(strlen(type)+strlen(f)));
+		sprintf(b, f, type);
+		asexc = ArrayStoreException(b);
+		KFREE(b);
+		throwException(asexc);
 	} 	 
 
 	/* Make sure we'll keep in the array boundaries */ 	 
@@ -567,13 +587,31 @@
 #endif 	 
 	} else {
 		if (CLASS_IS_PRIMITIVE(sclass) || CLASS_IS_PRIMITIVE(dclass)) {
-			throwException (ArrayStoreException);
+		  Hjava_lang_Throwable* asexc;
+		  const char* f = "incompatible array types `%s' and `%s'";
+		  const char *stype = CLASS_CNAME(sclass);
+		  const char *dtype = CLASS_CNAME(dclass);
+		  char *b;
+		  b = checkPtr(KMALLOC(strlen(stype)+strlen(dtype)+strlen(f)));
+		  sprintf(b, f, stype, dtype);
+		  asexc = ArrayStoreException(b);
+		  KFREE(b);
+		  throwException(asexc);
 		}
 
 		for (; len > 0; len -= sizeof(Hjava_lang_Object*)) { 	 
 			Hjava_lang_Object* val = *(Hjava_lang_Object**)in; 	 
 			if (val != 0 && !instanceof(dclass, OBJECT_CLASS(val))) { 	 
-				throwException (ArrayStoreException);
+			  Hjava_lang_Throwable* asexc;
+			  const char* f = "can't store `%s' in array of type `%s'";
+			  const char *vtype = CLASS_CNAME(OBJECT_CLASS(val));
+			  const char *atype = CLASS_CNAME(dclass);
+			  char *b;
+			  b = checkPtr(KMALLOC(strlen(vtype)+strlen(atype)+strlen(f)));
+			  sprintf(b, f, vtype, atype);
+			  asexc = ArrayStoreException(b);
+			  KFREE(b);
+			  throwException(asexc);
 			}
 			*(Hjava_lang_Object**)out = val; 	 
 			in += sizeof(Hjava_lang_Object*); 	 

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
kaffe mailing list
[EMAIL PROTECTED]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to