feature request: ClassCastException with description

Archie Cobbs kaffe@rufus.w3.org
Tue, 28 Jul 1998 11:11:20 -0700 (PDT)


It would be nice if when kaffe generates a class cast exception, kaffe
could set the description string associated with the exception, to help
in debugging the program.

Below is a patch to do this; however, it's probably incomplete because:

  - It uses snprintf() which doesn't exist on all systems
  - Not sure if the result of CLASS_CNAME(c) is suitable for
    input to makeJavaString().

Could kaffe included an "official" version of this patch?

-Archie

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

Index: kaffe/kaffevm/errors.h
===================================================================
RCS file: /cvs/mod/net/kaffe/kaffe/kaffevm/errors.h,v
retrieving revision 1.1.1.2
diff -c -u -r1.1.1.2 errors.h
--- errors.h	1998/07/10 23:00:31	1.1.1.2
+++ errors.h	1998/07/28 18:10:22
@@ -41,7 +41,7 @@
 #define IncompatibleClassChangeError NEW_LANG_EXCEPTION(IncompatibleClassChangeError)
 #define IllegalAccessError NEW_LANG_EXCEPTION(IllegalAccessError)
 #define NegativeArraySizeException NEW_LANG_EXCEPTION(NegativeArraySizeException)
-#define ClassCastException NEW_LANG_EXCEPTION(ClassCastException)
+#define ClassCastException(M) NEW_LANG_EXCEPTION_MESSAGE(ClassCastException, M)
 #define IllegalMonitorStateException NEW_LANG_EXCEPTION(IllegalMonitorStateException)
 #define NullPointerException NEW_LANG_EXCEPTION(NullPointerException)
 #define ArrayIndexOutOfBoundsException NEW_LANG_EXCEPTION(ArrayIndexOutOfBoundsException)
Index: kaffe/kaffevm/soft.c
===================================================================
RCS file: /cvs/mod/net/kaffe/kaffe/kaffevm/soft.c,v
retrieving revision 1.1.1.2
diff -c -u -r1.1.1.2 soft.c
--- soft.c	1998/07/10 23:00:42	1.1.1.2
+++ soft.c	1998/07/28 18:10:22
@@ -350,7 +350,10 @@
 soft_checkcast(Hjava_lang_Class* c, Hjava_lang_Object* o)
 {
 	if (o != 0 && !instanceof(c, OBJECT_CLASS(o))) {
-		throwException(ClassCastException);
+		char buf[100];
+		snprintf(buf, sizeof(buf), "can't cast object to type %s",
+		  CLASS_CNAME(c));
+		throwException(ClassCastException(buf));
 	}
 	return (o);
 }