< prev index next >

src/hotspot/share/oops/objArrayKlass.cpp

Print this page
rev 50570 : 8204943: Improve message of ArrayStoreException.

@@ -233,28 +233,48 @@
       ArrayAccess<ARRAYCOPY_DISJOINT>::oop_arraycopy(s, src_offset, d, dst_offset, length);
     } else {
       // slow case: need individual subtype checks
       // note: don't use obj_at_put below because it includes a redundant store check
       if (!ArrayAccess<ARRAYCOPY_DISJOINT | ARRAYCOPY_CHECKCAST>::oop_arraycopy(s, src_offset, d, dst_offset, length)) {
-        THROW(vmSymbols::java_lang_ArrayStoreException());
+        ResourceMark rm(THREAD);
+        stringStream ss;
+        if (!bound->is_subtype_of(stype)) {
+          ss.print("arraycopy: type mismatch: can not copy %s[] into %s[]",
+                   stype->external_name(), bound->external_name());
+        } else {
+          // oop_arraycopy should return the index in the source array that
+          // contains the problematic oop.
+          ss.print("arraycopy: element type mismatch: can not cast one of the elements"
+                   " of %s[] to the type of the destination array, %s",
+                   stype->external_name(), bound->external_name());
+        }
+        THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());
       }
     }
   }
 }
 
 void ObjArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d,
                                int dst_pos, int length, TRAPS) {
   assert(s->is_objArray(), "must be obj array");
 
   if (!d->is_objArray()) {
-    THROW(vmSymbols::java_lang_ArrayStoreException());
+    ResourceMark rm(THREAD);
+    stringStream ss;
+    if (d->is_typeArray()) {
+      ss.print("arraycopy: type mismatch: can not copy object array[] into %s[]",
+               type2name_tab[ArrayKlass::cast(d->klass())->element_type()]);
+    } else {
+      ss.print("arraycopy: destination type %s is not an array", d->klass()->external_name());
+    }
+    THROW_MSG(vmSymbols::java_lang_ArrayStoreException(), ss.as_string());
   }
 
   // Check is all offsets and lengths are non negative
   if (src_pos < 0 || dst_pos < 0 || length < 0) {
     // Pass specific exception reason.
-    ResourceMark rm;
+    ResourceMark rm(THREAD);
     stringStream ss;
     if (src_pos < 0) {
       ss.print("arraycopy: source index %d out of bounds for object array[%d]",
                src_pos, s->length());
     } else if (dst_pos < 0) {

@@ -267,11 +287,11 @@
   }
   // Check if the ranges are valid
   if ((((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) ||
       (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length())) {
     // Pass specific exception reason.
-    ResourceMark rm;
+    ResourceMark rm(THREAD);
     stringStream ss;
     if (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) {
       ss.print("arraycopy: last source index %u out of bounds for object array[%d]",
                (unsigned int) length + (unsigned int) src_pos, s->length());
     } else {
< prev index next >