title: JNI crash when called with a String argument
body: <p>I am trying to call a function implemented in C from my Android code. The code flow is this:</p>
  
  <p>In the onCreate() of my main activity, I have this:</p>
  
  <pre><code>    TestClass tc = new TestClass();
      tc.act();
  </code></pre>
  
  <p>This is TestClass:</p>
  
  <pre><code>package bar.foo;
  
  public class TestClass {
      static {
          System.loadLibrary("testclass");
      }
      public native void doStuff1(String s);
      public native void doStuff2(String s1, String s2);
  
      TestClass() { }
      public void act() {
          doStuff1 ("Foo");
          doStuff2 ("Bar", "Baz");
      }
  }
  </code></pre>
  
  <p>And testclass.c is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;jni.h&gt;
  #include &lt;android/log.h&gt;
  
  #define alprint __android_log_print
  
  #define METHOD_SIGNATURE_1 Java_bar_foo_TestClass_doStuff1
  #define METHOD_SIGNATURE_2 Java_bar_foo_TestClass_doStuff2
  
  void METHOD_SIGNATURE_1(JNIEnv* env, jstring s) {
  
      const char *ns;
      int jsLen;
  
      /* Extract strings */
      ns = (*env)-&gt;GetStringUTFChars(env, s, NULL);
          jsLen = (*env)-&gt;GetStringUTFLength(env, s);
  
          alprint(6, "doStuff1", "Text = %s [%d]\n", ns, jsLen);
  
      (*env)-&gt;ReleaseStringUTFChars(env, s, ns);
  
          return;
  }
  
  void METHOD_SIGNATURE_2(JNIEnv* env, jstring s1, jstring s2) {
  
      const char *ns1;
      const char *ns2;
      int js1Len;
          int js2Len;
  
      /* Extract strings */
      ns1 = (*env)-&gt;GetStringUTFChars(env, s1, NULL);
          js1Len = (*env)-&gt;GetStringUTFLength(env, s1);
          ns2 = (*env)-&gt;GetStringUTFChars(env, s2, NULL);
          js2Len = (*env)-&gt;GetStringUTFLength(env, s2);
  
          alprint(6, "doStuff2", "Text(1) = %s [%d]\n", ns1, js1Len);
          alprint(6, "doStuff2", "Text(2) = %s [%d]\n", ns2, js2Len);
  
      (*env)-&gt;ReleaseStringUTFChars(env, s1, ns1);
      (*env)-&gt;ReleaseStringUTFChars(env, s2, ns2);
  
          return;
  }
  </code></pre>
  
  <p>This compiles fine, and launches on my Android device (a Nexus 5 running Android 5.1) but crashes upon launch with:</p>
  
  <pre><code>JNI DETECTED ERROR IN APPLICATION: jstring has wrong type: bar.foo.TestClass
  </code></pre>
  
  <p>The full crash dump is here: <a href="http://pastebin.com/C0M98Uzb" rel="noreferrer">http://pastebin.com/C0M98Uzb</a></p>
  
  <p>I have been breaking my head over this one since yesterday evening; does anyone know what this is about?</p>