libgcj doesn't build proper reflection data for interpreted classes. The problem is that the format of the names of the exception classes differs between native and interpreted code. For native code we get "LMyException;", and for interpreted code we get "MyException". libgcj is written to expect "LMyException;". What you end up with in Method is a Class[] filled with null instead of a proper array of exception classes. Release: 3.3 20021031 (experimental) Environment: System: Linux build.tokyo.redhat.com 2.4.18-14smp #1 SMP Wed Sep 4 12:34:47 EDT 2002 i686 i686 i386 GNU/Linux Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../../FSF/GCC/HEAD/gcc/configure --prefix=/home/green/latest/i --enable-threads --enable-languages=c,c++,java : (reconfigured) How-To-Repeat: I don't have a simple test case prepared. However, all you need to do to trigger this is call Method.toString() on a Method of an interpreted class which throws an exception.
Fix: This work-around seems useful for now. Another fix would be to change the format of the meta-data emitted by the compiler. Index: java/lang/reflect/natMethod.cc =================================================================== RCS file: /cvs/gcc/gcc/libjava/java/lang/reflect/natMethod.cc,v retrieving revision 1.29 diff -2 -c -p -r1.29 natMethod.cc *** java/lang/reflect/natMethod.cc 27 Aug 2002 23:57:17 -0000 1.29 --- java/lang/reflect/natMethod.cc 31 Oct 2002 17:16:00 -0000 *************** java::lang::reflect::Method::getType () *** 208,213 **** jclass *elts = elements (exception_types); for (int i = 0; i < count; ++i) ! elts[i] = _Jv_FindClassFromSignature (method->throws[i]->data, ! declaringClass->getClassLoader ()); } --- 208,228 ---- jclass *elts = elements (exception_types); for (int i = 0; i < count; ++i) ! { ! char *c = (char *) method->throws[i]->data; ! int len = strlen (c); ! if (c[0] != 'L' && c[len-1] != ';') ! { ! char name[len+3]; ! name[0] = 'L'; ! strcpy (&name[1], c); ! name[len+1] = ';'; ! name[len+2] = 0; ! elts[i] = _Jv_FindClassFromSignature (name, ! declaringClass->getClassLoader ()); ! } ! else ! elts[i] = _Jv_FindClassFromSignature (method->throws[i]->data, ! declaringClass->getClassLoader ()); ! } }
From: Tom Tromey <tromey@redhat.com> To: Anthony Green <green@build.tokyo.redhat.com> Cc: gcc-gnats@gcc.gnu.org Subject: Re: java/8415: reflection bug: exception info for Method Date: 01 Nov 2002 14:42:16 -0700 Anthony> I don't have a simple test case prepared. I wrote one. I'll check it in. Anthony> This work-around seems useful for now. Another fix would be Anthony> to change the format of the meta-data emitted by the Anthony> compiler. I prefer the latter. I have a patch that I'm testing. Tom
From: tromey@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: java/8415 Date: 2 Nov 2002 00:19:53 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: tromey@gcc.gnu.org 2002-11-01 16:19:53 Modified files: libjava/testsuite: ChangeLog Added files: libjava/testsuite/libjava.lang: pr8415.java pr8415.out Log message: For PR java/8415: * libjava.lang/pr8415.java: New file. * libjava.lang/pr8415.out: New file. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.224&r2=1.225 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/pr8415.java.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.lang/pr8415.out.diff?cvsroot=gcc&r1=NONE&r2=1.1
Responsible-Changed-From-To: unassigned->tromey Responsible-Changed-Why: I'm handling this
State-Changed-From-To: open->closed State-Changed-Why: I've checked in the fix
From: tromey@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: java/8415 Date: 2 Nov 2002 21:33:30 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: tromey@gcc.gnu.org 2002-11-02 13:33:30 Modified files: libjava : ChangeLog prims.cc libjava/java/lang/reflect: natMethod.cc Log message: For PR java/8415: * java/lang/reflect/natMethod.cc (getType): Use _Jv_FindClass. * prims.cc (_Jv_FindClassFromSignature): Indentation fix. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.1500&r2=1.1501 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/prims.cc.diff?cvsroot=gcc&r1=1.73&r2=1.74 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/reflect/natMethod.cc.diff?cvsroot=gcc&r1=1.29&r2=1.30
From: tromey@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: java/8415 Date: 2 Nov 2002 21:33:54 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: tromey@gcc.gnu.org 2002-11-02 13:33:54 Modified files: gcc/java : ChangeLog class.c Log message: * class.c (make_method_value): Put class name, not signature, into `throws' field. For PR java/8415. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1079&r2=1.1080 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/class.c.diff?cvsroot=gcc&r1=1.136&r2=1.137