Correctly throw AssertionError
The AssertionError constructor containing a string is not able to be
properly called via the throwNew API. Instead, the AssertionError
object must be manually created and thrown.
Bug: 115686051
Test: Verified that assertion message is displayed properly if the
test encounters a failure condition.
Change-Id: I2984c220ffcccf5beaa0ae1624898f570d0f46d6
diff --git a/tests/sensor/jni/nativeTestHelper.cpp b/tests/sensor/jni/nativeTestHelper.cpp
index 3c7df9a..69eeba6 100644
--- a/tests/sensor/jni/nativeTestHelper.cpp
+++ b/tests/sensor/jni/nativeTestHelper.cpp
@@ -33,7 +33,11 @@
jclass exClass;
const char *className = "java/lang/AssertionError";
exClass = env->FindClass(className);
- env->ThrowNew(exClass, msg);
+ jmethodID constructor = env->GetMethodID(exClass, "<init>",
+ "(Ljava/lang/String;Ljava/lang/Throwable;)V");
+ jstring msgStr = env->NewStringUTF(msg);
+ jobject exception = env->NewObject(exClass, constructor, msgStr, nullptr);
+ env->Throw(static_cast<jthrowable>(exception));
free(msg);
}