Bug 23739 - JNI: IsAssignableFrom reverses arguments
Summary: JNI: IsAssignableFrom reverses arguments
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.0.2
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-05 18:51 UTC by Thomas Fitzsimmons
Modified: 2005-09-06 16:04 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-05 21:31:13


Attachments
test case demonstrating incorrect IsAssignableFrom results (671 bytes, application/x-gzip)
2005-09-05 18:54 UTC, Thomas Fitzsimmons
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Fitzsimmons 2005-09-05 18:51:00 UTC
libgcj's IsAssignableFrom returns results opposite to those returned by Sun. 
This seems to be a simple mix-up of the meanings of the function's two arguments.
Comment 1 Thomas Fitzsimmons 2005-09-05 18:54:20 UTC
Created attachment 9669 [details]
test case demonstrating incorrect IsAssignableFrom results

To build the test case, run "make" in the iaf directory.

$ make JAVA=gij run
LD_LIBRARY_PATH=. $JAVA iaf
B extends A
isAssignableFrom (A, B): 1
isAssignableFrom (B, A): 0

$ make JAVA=/usr/java/jdk1.5.0_01/bin/java run
LD_LIBRARY_PATH=. $JAVA iaf
B extends A
isAssignableFrom (A, B): 0
isAssignableFrom (B, A): 1
Comment 2 Tom Tromey 2005-09-05 21:24:23 UTC
How embarrassing.

One question is whether we ought to change CNI to conform.
I suspect the answer is 'yes', for clarity's sake.
Comment 3 Tom Tromey 2005-09-05 21:31:13 UTC
I'm testing a patch
Comment 4 Bryce McKinlay 2005-09-05 22:20:09 UTC
IMO Sun actually got it wrong here ;-) Reading function arguments from
left-to-right, I'd expect the first argument to be the context ("Is") and the
second to be the class refered to in (the "From").

Having said that, it is rather confusing that the order is reversed between JNI
and libgcj's internal function. I agree we should fix it, though there are a lot
of callers to update. It is not an issue for CNI, because IsAssignableFrom is
not exposed as a public CNI function.
Comment 5 GCC Commits 2005-09-06 16:01:49 UTC
Subject: Bug 23739

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2005-09-06 16:01:32

Modified files:
	libjava        : ChangeLog jni.cc link.cc prims.cc 
	libjava/java/lang: natClass.cc 
	libjava/java/lang/reflect: natMethod.cc 
	libjava/testsuite: Makefile.in 
Added files:
	libjava/testsuite/libjava.jni: pr23739.c pr23739.java 
	                               pr23739.out 

Log message:
	PR libgcj/23739:
	* testsuite/libjava.jni/pr23739.c: New file.
	* testsuite/libjava.jni/pr23739.java: New file.
	* testsuite/libjava.jni/pr23739.out: New file.
	* jni.cc (_Jv_JNI_IsAssignableFrom): Reversed arguments.
	* java/lang/reflect/natMethod.cc (invoke): Updated.
	* java/lang/natClass.cc (isAssignableFrom): Updated.
	(isInstance): Likewise.
	(_Jv_IsAssignableFrom): Reversed arguments.
	(_Jv_IsInstanceOf): Updated.
	(_Jv_CheckCast): Likewise.
	(_Jv_CheckArrayStore): Likewise.
	(_Jv_IsAssignableFromSlow): Reversed arguments.
	(_Jv_InterfaceAssignableFrom): Likewise.
	* link.cc (verify_type_assertions): Updated.
	* prims.cc (_Jv_CheckAccess): Updated.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3733&r2=1.3734
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/jni.cc.diff?cvsroot=gcc&r1=1.99&r2=1.100
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/link.cc.diff?cvsroot=gcc&r1=1.17&r2=1.18
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/prims.cc.diff?cvsroot=gcc&r1=1.112&r2=1.113
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/natClass.cc.diff?cvsroot=gcc&r1=1.89&r2=1.90
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/reflect/natMethod.cc.diff?cvsroot=gcc&r1=1.46&r2=1.47
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/Makefile.in.diff?cvsroot=gcc&r1=1.86&r2=1.87
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.jni/pr23739.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.jni/pr23739.java.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/testsuite/libjava.jni/pr23739.out.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 GCC Commits 2005-09-06 16:03:27 UTC
Subject: Bug 23739

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tromey@gcc.gnu.org	2005-09-06 16:03:12

Modified files:
	libjava        : ChangeLog jni.cc 

Log message:
	PR libgcj/23739:
	* jni.cc (_Jv_JNI_IsAssignableFrom): Reversed arguments.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.94&r2=1.3391.2.95
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/jni.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.95.2.1&r2=1.95.2.2

Comment 7 Tom Tromey 2005-09-06 16:04:04 UTC
Fix checked in.