title: JNI passing a null argument to Java method
body: <p><strong>EDIT</strong></p>
  
  <p>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:</p>
  
  <p><em>Is it safe to pass NULL/0/nullptr to Java method through JNI if the argument is supposed to be null?</em></p>
  
  <p>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.</p>
  
  <p><strong>OLD QUESTION</strong></p>
  
  <p>Is it possible to call Java method with a null argument when using JNI?</p>
  
  <p>I've tried passing null (either 0, NULL or nullptr), but that causes Segmentation fault. I have also tried <code>NewGlobalRef</code> with null argument, but that just returns null.</p>
  
  <p>Assume following Java code:</p>
  
  <pre class="lang-java prettyprint-override"><code>class Main {
    public void javaFoo(Object o) {
      ...
    }
  }
  </code></pre>
  
  <p>Calling this method from C++ will look similar to this:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>env-&gt;CallVoidMethod(object, javaFooID, value);
  </code></pre>
  
  <p>Now what do I have to do if I want <code>value</code> to be null?</p>
  
  <p>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:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void setFoo(Object a, Object b, Object c, Object d) {
    ... // any parameter can be null
  }
  </code></pre>