Java jni: What's Wrong here?

  • From: "John J. Boyer" <john.boyer@xxxxxxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 29 Jan 2011 03:35:59 -0600

One of the functgions in my Java bindings for liblouisutdml (Which will 
be used in BrailleBlaster) requires a variable number of arguments. The 
native method diclaration handles this with String[] The C function gets 
a jObjectArray when it is called. The function which I am pasting below 
is supposed to get each argument in turn according to the value of the 
index parameter. It produces a segmentation fault. I think the problem 
is in the line that attempts to procuce a C character string from the 
Jobject. Suggestions? Thanks.

JNIEXPORT const jbyte *JNICALL
getArg (JNIEnv * env, jobject this, jobjectArray args, jint index)
{
  static jobject curObj = NULL;
  static const jbyte *curArg = NULL;
  if (args == NULL)
    return NULL;
  if (curObj != NULL || index == -1)
    {
      if (curArg != NULL)
        (*env)->ReleaseStringUTFChars (env, curObj, curArg);
      curArg = NULL;
      curObj = NULL;
    }
  curObj = (*env)->GetObjectArrayElement (env, args, index);
  curArg = (*env)->GetStringUTFChars (env, curObj, NULL);
  return curArg;
}

-- 
John J. Boyer; President, Chief Software Developer
Abilitiessoft, Inc.
http://www.abilitiessoft.com
Madison, Wisconsin USA
Developing software for people with disabilities

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: