title: Invalid indirect reference on NewObject call
body: <p>OK, so I have the native code below.
  I'm trying to return an array of FilePermissionInfo from it, populated with some data returned by stat(). 
  The problem is that I get the following error when NewObject is called the first time:</p>
  
  <blockquote>
    <p>06-15 20:25:17.621: W/dalvikvm(2287): Invalid indirect reference
    0x40005820 in decodeIndirectRef 06-15 20:25:17.621: E/dalvikvm(2287):
    VM aborting</p>
  </blockquote>
  
  <p>It's odd, because the only reference object I have is the jclass (for FilePermissionInfo) and I turn it to a global reference.</p>
  
  <p>The code is:</p>
  
  <pre><code>JNIEXPORT jobjectArray JNICALL
  Java_com_mn_rootscape_utils_NativeMethods_getFilesPermissions( JNIEnv* env, jobject thizz, jobjectArray filePathsArray ) 
  {
  jobjectArray result;
  int size = (*env)-&gt;GetArrayLength(env, filePathsArray);
  jboolean isCopy;
  
  jclass filePermInfoCls = (*env)-&gt;FindClass(env, kFilePermissionInfoPath);
  if(!filePermInfoCls)
  {
      LOGE("getFilesPermissions: failed to get class reference.");
      return NULL;
  }
  
  gFilePermInfoClass = (jclass)(*env)-&gt;NewGlobalRef(env, filePermInfoCls);
  LOGI("got gFilePermInfoClass");
  
  jmethodID filePermInfoClsConstructor = (*env)-&gt;GetMethodID(env, gFilePermInfoClass, "&lt;init&gt;", kFilePermInfoConstructorSig);
  if(!filePermInfoClsConstructor)
  {
      LOGE("getFilesPermissions: failed to get method reference.");
      return NULL;
  }
  
  struct stat sb;
  
  LOGI("starting...");
  result = (jobjectArray)(*env)-&gt;NewObjectArray(env, size, gFilePermInfoClass, NULL);
  for(int i = 0; i != size; ++i) 
  {
      jstring string = (jstring) (*env)-&gt;GetObjectArrayElement(env, filePathsArray, i);
  const char *rawString = (*env)-&gt;GetStringUTFChars(env, string, &amp;isCopy);    
  
      if(stat(rawString, &amp;sb) == -1) 
      {
          LOGE("stat error for: %s", rawString);
      }
  
      LOGI("%ld %ld %ld %ld %ld %ld %ld %ld", sb.st_dev, sb.st_mode, sb.st_nlink, sb.st_uid, sb.st_gid, sb.st_atime, sb.st_mtime, sb.st_ctime);
  
      jobject permInfo = (*env)-&gt;NewObject(env, 
                              gFilePermInfoClass, 
                              filePermInfoClsConstructor, 
                              (long)sb.st_dev,
                              (long)sb.st_mode,
                              (long)sb.st_nlink,
                              (long)sb.st_uid,
                              (long)sb.st_gid,
                              (long)sb.st_atime,
                              (long)sb.st_mtime,
                              (long)sb.st_ctime,
                              "",
                              "",
                              1,
                              "");
  
      LOGI("xxx1");
      (*env)-&gt;SetObjectArrayElement(env, result, i, permInfo);
      LOGI("xxx2");
      (*env)-&gt;ReleaseStringUTFChars(env, string, rawString);
      LOGI("xxx3");
  }
  
  (*env)-&gt;DeleteLocalRef(env, filePermInfoCls);
  
  return result;
  </code></pre>
  
  <p>}</p>
  
  <p>The Java class constructor signature and path are:</p>
  
  <pre><code>const char* kFilePermissionInfoPath = "com/mn/rootscape/utils/FilePermissionInfo";
  const char* kFilePermInfoConstructorSig = "(JJJJJJJJLjava/lang/String;Ljava/lang/String;ZLjava/lang/String;)V";
  </code></pre>
  
  <p>Please note that if I call NewObject on the default constructor then it works fine.</p>