summaryrefslogtreecommitdiff
path: root/src/java_lang_System.cc
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2012-01-10 11:05:48 -0800
committer Elliott Hughes <enh@google.com> 2012-01-10 11:05:48 -0800
commit025c5de6aab0719c77a19d62b2df80291ec225e6 (patch)
treedd3d0a8e10738aae7cf06d530cb20d054eac1e0e /src/java_lang_System.cc
parenta68a1cb0769d618331d65a94d1a9cde68fcbb5ea (diff)
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
Diffstat (limited to 'src/java_lang_System.cc')
-rw-r--r--src/java_lang_System.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/java_lang_System.cc b/src/java_lang_System.cc
index 72cf0926d5..985e753b11 100644
--- a/src/java_lang_System.cc
+++ b/src/java_lang_System.cc
@@ -210,9 +210,10 @@ void System_arraycopy(JNIEnv* env, jclass, jobject javaSrc, jint srcPos, jobject
// 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 @@ void System_arraycopy(JNIEnv* env, jclass, jobject javaSrc, jint srcPos, jobject
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",