title: Should you call ReleaseStringUTFChars if GetStringUTFChars returned a copy?
body: <p>The book "Essential JNI: Java Native Interface" by Rob Gordon contains the following code example to convert a jstring to a C string:</p>
  
  <pre><code>const char* utf_string;
  jboolean isCopy;
  utf_string = env-&gt;GetStringUTFChars(str, &amp;isCopy);
  /* ... use string ... */
  if (isCopy == JNI_TRUE) {
      env-&gt;ReleaseStringUTFChars(str, utf_string);
  }
  </code></pre>
  
  <p>Note that it only calls <code>ReleaseStringUTFChars</code> if <code>isCopy</code> is true. </p>
  
  <p>But the book <a href="http://java.sun.com/docs/books/jni/html/objtypes.html#5161" rel="noreferrer">Java Native Interface: Programmer's Guide and Specification</a> (alternate link: <code>http://192.9.162.55/docs/books/jni/html/objtypes.html#5161</code>) says:</p>
  
  <blockquote>
    <p>The ReleaseString-Chars call is
    necessary whether GetStringChars has
    set *isCopy to JNI_TRUE or JNI_FALSE.
    ReleaseStringChars either frees the
    copy or unpins the instance, depending
    upon whether GetStringChars has
    returned a copy or not.</p>
  </blockquote>
  
  <p>I am correct in assuming this is a bug in Gordon's book?</p>