EDIT
Finally, it turned out that the problem was caused by the fact that the null value was not null, because one of the constructors did not initialize the value to zero. With this knowledge, I would like to change my question as follows:
Is it safe to pass NULL / 0 / nullptr to the Java method via JNI if the argument should be null?
The sources that I have found so far have yielded mixed results - some of them say that NULL in C and null in Java are the same when using JNI. Some, like those related to the answer to remudada, suggest that this may not be entirely correct.
OLD QUESTION
Is it possible to call a Java method with a null argument when using JNI?
I tried passing null (0, NULL or nullptr), but this causes a segmentation error. I also tried NewGlobalRefwith a null argument, but that just returns null.
Assume the following Java code:
class Main {
public void javaFoo(Object o) {
...
}
}
A call to this method from C ++ will look something like this:
env->CallVoidMethod(object, javaFooID, value);
Now, what do I need to do if I want to valuebe empty?
The problem is that I cannot easily avoid passing null objects. There are various setters that have several parameters that 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) {
...
}