lundi 29 juin 2015

SIGSEGV in CallVoidMethod jni


I have a java appliction with some jni native methods. One of them is readFile, and it is called like this:

OutputStream outStream = null;
File file = new File("Alf.txt");

try {
    outStream = new FileOutputStream(file);
    myObject.readFile("TestFile.txt",outStream);
...

in my jni implementation I do :

JNIEXPORT jint JNICALL Java_com_example_mylib_SomeClass_readFile
(JNIEnv *env, jclass, jstring java_string, jobject stream) {


jclass classOutputStream = env->FindClass("java/io/OutputStream");
if (classOutputStream == NULL)
{
      Log::err("classOutputStream == NULL;");
      return -1;
}
jmethodID OutputStream_write_ID = env->GetMethodID(classOutputStream, "write", "([BII)V");
if (OutputStream_write_ID == NULL)
{
   return -1;
}
char* buf = "hello";

env->CallVoidMethod((jobject)stream, OutputStream_write_ID,buf,0,5);

and when I call CallVoidMethod I get

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f4a85a5e1e1, pid=25597, tid=139958068348672
#
# JRE version: Java(TM) SE Runtime Environment (8.0_25-b17) (build 1.8.0_25-b17)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x6ad1e1]  jni_GetArrayLength+0xb1
#
# Failed to write core dump. Core dumps have been disabled. To enable  core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /.../hs_err_pid25597.log

I checked - no variables are == NULL, what do I do wrong?


Aucun commentaire:

Enregistrer un commentaire