title: Convert char* to jstring in JNI, when char* is passed using va_arg
body: <p>Is it necessary to convert char* to jbyteArray, then call java String's contructor to generate a jstring? How else can it be done? Please help.   </p>
  
  <pre><code>static int testhandler(void *arg, ...)
   {
      int i;
      struct callback *cb = (struct callback *)arg;
  
      JNIEnv *env = cb-&gt;env;
      char *sig = cb-&gt;signature;
  
      jint size = (jint) strlen(sig);
      jint size1;
      va_list arguments;
  
      jobjectArray return_array;
      jclass obj_class;
      jbyteArray bytes;
      jstring str;
  
      obj_class = (*env)-&gt;FindClass(env, "java/lang/Object");
      return_array = (*env)-&gt;NewObjectArray(env, size, obj_class, NULL);
  
      va_start(arguments, arg);
  
      for (i = 0; i &lt; size; i++) {
          jclass clazz;
          jmethodID id;
          jobject obj;
          jobject encoding;
          switch (sig[i]) {
              case 'i': {
                  clazz = (*env)-&gt;FindClass(env, "java/lang/Integer");
                  id = (*env)-&gt;GetMethodID(env, clazz, "&lt;init&gt;", "(I)V");
                  obj = (*env)-&gt;NewObject(env, clazz, id, va_arg(arguments, uint32_t));
                  (*env)-&gt;SetObjectArrayElement(env, return_array, i, obj);
                  break;
              }
              case 'l': {
                  clazz = (*env)-&gt;FindClass(env, "java/lang/Long");
                  id = (*env)-&gt;GetMethodID(env, clazz, "&lt;init&gt;", "(J)V");
                  obj = (*env)-&gt;NewObject(env, clazz, id, va_arg(arguments, uint64_t));
                  (*env)-&gt;SetObjectArrayElement(env, return_array, i, obj);
                  break;
              }
              case 's': {
                  clazz = (*env)-&gt;FindClass(env, "java/lang/String");
                  size1 = (jint) strlen(va_arg(arguments, char *));
                  id = (*env)-&gt;GetMethodID(env, clazz, "&lt;init&gt;", "([BLjava/lang/String;)V");
  
                  encoding = (*env)-&gt;NewStringUTF(env, va_arg(arguments, char *)); 
                  bytes = (*env)-&gt;NewByteArray(env, size1); 
                  (*env)-&gt;SetByteArrayRegion(env, bytes, 0, size1, (jbyte *)(va_arg(arguments, char *)));
  
                  str = (jstring)(*env)-&gt;NewObject(env, clazz, id , bytes);
                  obj = (*env)-&gt;NewObject(env, clazz, id, str);
                  (*env)-&gt;SetObjectArrayElement(env, return_array, i, obj);
                  break;
              }
              default: {
                  printf("unknown signature char '%c'\n", sig[i]);
              }
          }
  
      }
      va_end(arguments);
      (*env)-&gt;CallVoidMethod(env, cb-&gt;handler, cb-&gt;id, return_array);
  
      return 0;
  }
  </code></pre>