EDIT
I've finally found out that the problem was caused by the null value not being null after all, because one of the constructors didn't initialize the value to zero. With this knowledge, I'd like to reword my question to following:
Is it safe to pass NULL/0/nullptr to Java method through JNI if the argument is supposed to be null?
The sources I found so far gave mixed results – some of them say that NULL in C and null in Java are the same thing when using JNI. Some, like the one linked in the remudada's answer, suggests that it may not be entirely correct.
OLD QUESTION
Is it possible to call Java method with a null argument when using JNI?
I've tried passing null (either 0, NULL or nullptr), but that causes Segmentation fault. I have also tried NewGlobalRef with null argument, but that just returns null.
Assume following Java code:
class Main {
public void javaFoo(Object o) {
...
}
}
Calling this method from C++ will look similar to this:
env->CallVoidMethod(object, javaFooID, value);
Now what do I have to do if I want value to be null?
The problem is that I can't easily avoid passing null objects. There are various setters which have multiple parameters which may or may not be null and where null serves as an invalid value:
public void setFoo(Object a, Object b, Object c, Object d) {
... // any parameter can be null
}