1

I need call native method like that:

java code:

private native Object SendFiles(String strEmail, DeviceInfo info, String [] arrFiles, int cntFiles, ID idRequest);

call SendFiles();

SendFiles(strEmail, null, arrFiles, cntFiles, requestID);

and c++ code:

jobject Java_com_xxxxx_xxxxx_controller_CoreController_SendFiles(JNIEnv *pEnv, jobject obj, jstring strEmail, jobject jinfo, jobjectArray jarrFiles, jint cntFiles, jobject jidRequest){
         .........

          if(jinfo == NULL)       // here crashes !!!!!!!
             doSomething();

         ............
}

Java 'null' can be sent to c 'NULL'?

how i can do this?

Phil
  • 35,852
  • 23
  • 123
  • 164
koleanu
  • 495
  • 5
  • 20
  • 1
    Is it really there where it crashes or are you accessing jinfo elsewhere? To me it seems that doSomething is only processed if jinfo is not available, but I don't see any mechanism to avoid execution of other code? – junix Feb 21 '13 at 21:49

2 Answers2

0

You can read up on c++ NULL checks on multiple posts, such as Checking for a null object in C++ or Checking if this is null or How do we check if a pointer is NULL pointer?

however this post seems to give the most straight-forward approach: Return a "NULL" object if search result not found

Community
  • 1
  • 1
Phil
  • 35,852
  • 23
  • 123
  • 164
  • It still doesn't explain the behavior as at least in JDK 1.7 `jobject` is defined as `typedef _jobject *jobject;` so it's not a call by reference, it's a call by pointer. And the pointer should be checkable for NULL or did I get something wrong? – junix Feb 21 '13 at 21:46
0

jobject is a pointer datatype on the C++ side. When you pass a null object from Java, C++ receives it as a NULL pointer. It's OK to compare.

The crash probably has to do with something else. Insert some diagnostic output and debug.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281