From 025c5de6aab0719c77a19d62b2df80291ec225e6 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 10 Jan 2012 11:05:48 -0800 Subject: 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 --- src/java_lang_System.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/java_lang_System.cc') 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", -- cgit v1.2.3-59-g8ed1b