Fix proxy return ClassCastException and add test.
Add test for Bug: 8250775 that doesn't effect ART. Expand test case further.
ClassCastException has no constructor expecting a cause and so using this
creates a JNI failure. Switch to not using a wrapped exception as the wrapping
itself wasn't adding information.
Change-Id: I32dd541e1a1022089ec993fa4f4646042c5bf1fa
diff --git a/src/runtime_support.cc b/src/runtime_support.cc
index 84a19cf..d76999c 100644
--- a/src/runtime_support.cc
+++ b/src/runtime_support.cc
@@ -440,11 +440,15 @@
mirror::Object* result_ref = soa.Decode<mirror::Object*>(result);
bool unboxed_okay = UnboxPrimitiveForResult(result_ref, result_type, result_unboxed);
if (!unboxed_okay) {
- soa.Self()->ThrowNewWrappedException("Ljava/lang/ClassCastException;",
- StringPrintf("Couldn't convert result of type %s to %s",
- PrettyTypeOf(result_ref).c_str(),
- PrettyDescriptor(result_type).c_str()
- ).c_str());
+ // UnboxPrimitiveForResult creates an IllegalArgumentException. Discard and create a
+ // meaningful ClassCastException.
+ DCHECK(soa.Self()->IsExceptionPending());
+ soa.Self()->ClearException();
+ soa.Self()->ThrowNewException("Ljava/lang/ClassCastException;",
+ StringPrintf("Couldn't convert result of type %s to %s",
+ PrettyTypeOf(result_ref).c_str(),
+ PrettyDescriptor(result_type).c_str()
+ ).c_str());
}
return result_unboxed;
}