title: Unexpected behaviour when inserting values into jobjectArray in JNI
body: <p>Im trying to create a 1D jobjectArray. When printing from inside the loop, &quot;args&quot; array prints correct values but once it is out of the loop, only the last element gets printed repeatedly.</p>
  <p>This is &quot;args&quot; jobjectArray declaration:</p>
  <pre><code>//Declare an object array
  jobjectArray args; 
  
  //Get the class of the object, generally ava/lang/Object is enough
  jclass objClass = (*env)-&gt;FindClass(env,&quot;java/lang/Object&quot;);
  
  //New object array
  args = (*env)-&gt;NewObjectArray(env,unum, objClass, 0);
  </code></pre>
  <p>This is the loop used to insert values into the jobjectArray:
  ( rec_msg[] struct array has correct values and there are no problems creating or inserting a jobject)</p>
  <pre><code>for(int i=0; i &lt; unum; i++ )
  {
         printf(&quot;\ni-%d---&quot;, i);
         (*env)-&gt;SetShortField(env,obj,stat,1);
         (*env)-&gt;SetShortField(env,obj,fnumber,rec_msg[i].filenum );            
         str = (*env)-&gt;NewStringUTF(env, rec_msg[i].username);
         (*env)-&gt;SetObjectField(env,obj,user, str);                
                  
         (*env)-&gt;SetObjectArrayElement(env,args, i, obj);
         printf(&quot;args fnum%d\n&quot;, (*env)-&gt;GetShortField(env, (*env)-&gt;GetObjectArrayElement(env, args, i), fnumber));
          
        
   }
  </code></pre>
  <p>The printf in here prints the values of fnum (a field in jobject) correctly as:</p>
  <pre><code>i-0-args fnum3
  
  i-1-args fnum2
  
  i-2-args fnum9
  </code></pre>
  <p>but after the lopp, I wrote a new simple loop as:</p>
  <pre><code>for(int i=0; i &lt; unum; i++ )
      {
      printf(&quot;\ni-%d ARGS fnum%d&quot;,i, (*env)-&gt;GetShortField(env, (*env)-&gt;GetObjectArrayElement(env, args, i), fnumber));
    }
  </code></pre>
  <p>this prints:</p>
  <pre><code>i-0 ARGS fnum9
  i-1 ARGS fnum9
  i-2 ARGS fnum9
  </code></pre>
  <p>ie the last object repeats. There are no statements between this loop and the previous. Im unable to know why the &quot;args&quot; jobjectrray repeats the last element when it prints fine inside the first loop. Please let me know if any other details are required.</p>