Avoid a benign race where the exception message might be misleading.

Report the type of the object that failed the type check, without
assuming that the array hasn't been mutated since.

Change-Id: I57cd5057ded3ea994c46aa1aabca62299dd5e7b7
diff --git a/src/java_lang_System.cc b/src/java_lang_System.cc
index 72cf092..985e753 100644
--- a/src/java_lang_System.cc
+++ b/src/java_lang_System.cc
@@ -210,9 +210,10 @@
   // we know is assignable to the destination array's component type.
   Class* lastAssignableElementClass = dstClass;
 
+  Object* o = NULL;
   int i = 0;
   for (; i < length; ++i) {
-    Object* o = srcObjects[i];
+    o = srcObjects[i];
     if (o != NULL) {
       Class* oClass = o->GetClass();
       if (lastAssignableElementClass == oClass) {
@@ -231,7 +232,7 @@
 
   Heap::WriteBarrierArray(dstArray, dstPos, length);
   if (i != length) {
-    std::string actualSrcType(PrettyTypeOf(srcObjects[i]));
+    std::string actualSrcType(PrettyTypeOf(o));
     std::string dstType(PrettyTypeOf(dstArray));
     self->ThrowNewExceptionF("Ljava/lang/ArrayStoreException;",
         "source[%d] of type %s cannot be stored in destination array of type %s",