Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

GetStringUTFChars results in fatal error

974625Nov 16 2012 — edited Nov 17 2012
Today I started developing a simple JNI extension for the very first time. So I fully expect that the error might be on my side, but after searching and reading quite some examples, I can't figure it out. It looks as I do everything correct at least.

I set up a netbeans 6.7 environment on OpenIndiana, as described on http://cnd.netbeans.org/docs/jni/nb6-linux/beginning-jni-linux.html

I succesfully created a class that was capable of running the Hello World in the end.

Then I created a function in java that looks like this;
public native long nativeFunction(String name);

I recreated the headers and I got a function that looks like this in my header;
JNIEXPORT jlong JNICALL Java_application_nativeFunction
(JNIEnv *, jobject, jstring);

Then I implemented it like this in my c-file;
JNIEXPORT jlong JNICALL Java_application_nativeFunction (JNIEnv *env, jobject obj, jstring name) {
jlong ret;
const char str = (env)->GetStringUTFChars(env, name,0);
ret=100;

(*env)->ReleaseStringUTFChars(env,str,name);
return ret;
}

If I comment the lines with GetStringUTFChars and ReleaseStringUTFChars in them, the java and c parts compile perfectly and if I call the function nativeFunction I nicely get a return of 100 with the still added nativeprint after it (hello world from c). When I add the previously mentioned lines, both parts compile nicely, but the run of the java-result end in this;

#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xfe6ec42e, pid=3148, tid=2
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Client VM (20.1-b02 mixed mode solaris-x86 )
# Problematic frame:
# V [libjvm.so+0xec42e] jni_GetStringUTFChars+0xe2
#
# An error report file with more information is saved as:
# /home/michael/NetBeansProjects/javaproject/hs_err_pid3148.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

Hello world from C



So the application doesn't crash, but for some reason it won't do the very needed JNI-part. Any ideas?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2012
Added on Nov 16 2012
2 comments
4,948 views