title: Call Java method taking String argument from C
body: <p>I have Java method taking one <code>java.lang.String</code> argument. When I call it from C, I always get SIGSEGV when calling <code>NewStringUTF</code>.</p>
  <p>How can I call the Java method with <code>char *</code> string?</p>
  <pre class="lang-java prettyprint-override"><code>// Java
  void doSomething(String str) { … }
  </code></pre>
  <pre class="lang-c prettyprint-override"><code>// C
  void Java_some_very_long_function_name(JNIEnv *env, jobject thi)
  {
      jclass clas = (*env)-&gt;GetObjectClass(env, thi);
      jmethodID method = (*env)-&gt;GetMethodID(env, clas, &quot;doSomething&quot;, &quot;(Ljava/lang/String;)V&quot;);
  
      jstring str = (*env)-&gt;NewStringUTF(env, strdup(&quot;My String&quot;)); // Segfaults here
  
      // TODO Call the method
  }
  </code></pre>
  <p>It is happening <strong>after</strong> the <code>NewStringUTF</code> executes, not during <code>NewStringUTF</code> call.</p>
  <pre><code>art::FaultManager::HandleFault(int, siginfo*, void*) 0x00000000eae9efa4
  art::art_fault_handler(int, siginfo*, void*) (.llvm.2308358812779254744) 0x00000000eae9eccb
  ___lldb_unnamed_symbol25$$app_process32 0x000000005c58cfe1
  ___lldb_unnamed_symbol2$$libc.so 0x00000000edd18180
  art::Thread::DecodeJObject(_jobject*) const 0x00000000eb244c3f
  &lt;unknown&gt; 0x00000000ec29f05d
  &lt;unknown&gt; 0x000000005c58b000
  Java_very_long_name foo.c:761
  […]
  </code></pre>