[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

One JNI Usage Bug in Java binding

From: Byeongcheol Lee <lineonking_at_gmail.com>
Date: Fri, 14 May 2010 16:58:20 -0500

Dear Subversion Developers:

My JNI bug detector (Jinn) found several bugs in the JavaHL. I'd like
to hear your opinion about the bug before filing all the bugs. The bug
appears the Line 774 in the following slice of source files.

subversion/bindings/javahl/native/CreateJ.cpp
....
 634 jobject
 635 CreateJ::NotifyInformation(const svn_wc_notify_t *wcNotify)
 636 {
....
 754 static jmethodID add_mid = 0;
....
 757 add_mid = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
....
 774 env->CallObjectMethod(jranges, add_mid, jrange);
....

The "add" method at Line 757 returns a Java boolean value, but the JNI
function at Line 774 expects that the "add" method returns a Java
reference. This usage violates usage rules in JNI specifcation.

"You should replace type in Call<type>Method with the Java type of the
method you are calling (or use one of the actual method calling
routine names from the table) and replace NativeType with the
corresponding native type for that routine."
[http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp4256]

I propose the following patch:

Index: subversion/bindings/javahl/native/CreateJ.cpp
===================================================================
--- subversion/bindings/javahl/native/CreateJ.cpp (revision 944458)
+++ subversion/bindings/javahl/native/CreateJ.cpp (working copy)
@@ -771,7 +771,7 @@
     if (JNIUtil::isJavaExceptionThrown())
       POP_AND_RETURN_NULL;

- env->CallObjectMethod(jranges, add_mid, jrange);
+ env->CallBooleanMethod(jranges, add_mid, jrange);
     if (JNIUtil::isJavaExceptionThrown())
       POP_AND_RETURN_NULL;

Regards,
Byeong
Received on 2010-05-14 23:58:50 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.