Add messages to the ArrayStoreExceptions thrown by arraycopy().

See bug 2396302.
diff --git a/libcore/luni/src/test/java/java/lang/AllTests.java b/libcore/luni/src/test/java/java/lang/AllTests.java
index 38da14a..d8b7ade 100644
--- a/libcore/luni/src/test/java/java/lang/AllTests.java
+++ b/libcore/luni/src/test/java/java/lang/AllTests.java
@@ -24,6 +24,7 @@
         TestSuite suite = new TestSuite();
         suite.addTestSuite(java.lang.FloatTest.class);
         suite.addTestSuite(java.lang.ProcessBuilderTest.class);
+        suite.addTestSuite(SystemTest.class);
         return suite;
     }
 }
diff --git a/libcore/luni/src/test/java/java/lang/SystemTest.java b/libcore/luni/src/test/java/java/lang/SystemTest.java
new file mode 100644
index 0000000..b6fc5de
--- /dev/null
+++ b/libcore/luni/src/test/java/java/lang/SystemTest.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+import junit.framework.TestCase;
+
+public class SystemTest extends TestCase {
+
+    public void testArrayCopyTargetNotArray() {
+        try {
+            System.arraycopy(new char[5], 0, "Hello", 0, 3);
+            fail();
+        } catch (ArrayStoreException e) {
+            assertEquals("source and destination must be arrays, but were "
+                    + "[C and Ljava/lang/String;", e.getMessage());
+        }
+    }
+
+    public void testArrayCopySourceNotArray() {
+        try {
+            System.arraycopy("Hello", 0, new char[5], 0, 3);
+            fail();
+        } catch (ArrayStoreException e) {
+            assertEquals("source and destination must be arrays, but were "
+                    + "Ljava/lang/String; and [C", e.getMessage());
+        }
+    }
+
+    public void testArrayCopyArrayTypeMismatch() {
+        try {
+            System.arraycopy(new char[5], 0, new Object[5], 0, 3);
+            fail();
+        } catch (ArrayStoreException e) {
+            assertEquals("source and destination arrays are incompatible: "
+                    + "[C and [Ljava/lang/Object;", e.getMessage());
+        }
+    }
+
+    public void testArrayCopyElementTypeMismatch() {
+        try {
+            System.arraycopy(new Object[] { null, 5, "hello" }, 0,
+                    new Integer[] { 1, 2, 3, null, null }, 0, 3);
+            fail();
+        } catch (ArrayStoreException e) {
+            assertEquals("source[2] of type Ljava/lang/String; cannot be "
+                    + "stored in destination array of type [Ljava/lang/Integer;",
+                    e.getMessage());
+        }
+    }
+}
diff --git a/vm/native/java_lang_System.c b/vm/native/java_lang_System.c
index e2533ed..dd76764 100644
--- a/vm/native/java_lang_System.c
+++ b/vm/native/java_lang_System.c
@@ -59,7 +59,10 @@
     }
     /* make sure it's an array */
     if (!dvmIsArray(srcArray) || !dvmIsArray(dstArray)) {
-        dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
+        dvmThrowExceptionFmt("Ljava/lang/ArrayStoreException;",
+            "source and destination must be arrays, but were %s and %s",
+            ((Object*)srcArray)->clazz->descriptor,
+            ((Object*)dstArray)->clazz->descriptor);
         RETURN_VOID();
     }
 
@@ -87,7 +90,9 @@
         int width;
 
         if (srcPrim != dstPrim || srcType != dstType) {
-            dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
+            dvmThrowExceptionFmt("Ljava/lang/ArrayStoreException;",
+                "source and destination arrays are incompatible: %s and %s",
+                srcClass->descriptor, dstClass->descriptor);
             RETURN_VOID();
         }
 
@@ -191,7 +196,10 @@
                     copyCount * width);
 
             if (copyCount != length) {
-                dvmThrowException("Ljava/lang/ArrayStoreException;", NULL);
+                dvmThrowExceptionFmt("Ljava/lang/ArrayStoreException;",
+                    "source[%d] of type %s cannot be stored in destination array of type %s",
+                    copyCount, srcObj[copyCount]->clazz->descriptor,
+                    dstClass->descriptor);
                 RETURN_VOID();
             }
         }