Merge "Switch fatalError to NPE"
am: d70e6c1fca
Change-Id: I15f2d9a4d7b59fb980e50a68a00b5673c826e694
diff --git a/header_only_include/nativehelper/scoped_primitive_array.h b/header_only_include/nativehelper/scoped_primitive_array.h
index 17f18a3..982f424 100644
--- a/header_only_include/nativehelper/scoped_primitive_array.h
+++ b/header_only_include/nativehelper/scoped_primitive_array.h
@@ -51,8 +51,8 @@
static inline size_t getArrayLength(JNIEnv* env, ARRAY_TYPE array) { \
return env->GetArrayLength(array); \
} \
- static inline void fatalError(JNIEnv* env, const char*msg) { \
- env->FatalError(msg); \
+ static inline void throwNullPointerException(JNIEnv* env) { \
+ jniThrowNullPointerException(env, nullptr); \
} \
using ArrayType = ARRAY_TYPE; \
}; \
@@ -84,7 +84,7 @@
mSize = -1;
mRawArray = nullptr;
if (!kNullable) {
- Traits::fatalError(mEnv, "javaArray is null");
+ Traits::throwNullPointerException(mEnv);
}
} else {
mSize = Traits::getArrayLength(mEnv, mJavaArray);
@@ -166,7 +166,7 @@
ScopedArrayRW(JNIEnv* env, ArrayType javaArray) : mEnv(env), mJavaArray(javaArray) {
if (mJavaArray == nullptr) {
- Traits::fatalError(mEnv, "javaArray is null");
+ Traits::throwNullPointerException(mEnv);
} else {
mSize = Traits::getArrayLength(mEnv, mJavaArray);
mRawArray = Traits::getArrayElements(mEnv, mJavaArray);
diff --git a/tests/scoped_primitive_array_test.cpp b/tests/scoped_primitive_array_test.cpp
index cba258c..d75a880 100644
--- a/tests/scoped_primitive_array_test.cpp
+++ b/tests/scoped_primitive_array_test.cpp
@@ -32,13 +32,13 @@
int getArrayElementsCallCount = 0;
int releaseArrayElementsCallCount = 0;
- bool aborted = false;
+ bool NPEThrown = false;
bool elementsUpdated = false;
void resetCallCount() {
getArrayElementsCallCount = 0;
releaseArrayElementsCallCount = 0;
- aborted = false;
+ NPEThrown = false;
elementsUpdated = false;
}
@@ -72,8 +72,8 @@
return array == LARGE_ARRAY ? LARGE_ARRAY_SIZE : SMALL_ARRAY_SIZE;
}
- static inline void fatalError(JNIEnv* env, const char*) {
- reinterpret_cast<TestContext*>(env)->aborted = true;
+ static inline void throwNullPointerException(JNIEnv* env) {
+ reinterpret_cast<TestContext*>(env)->NPEThrown = true;
}
using ArrayType = jTestTypeArray;
@@ -99,7 +99,7 @@
}
EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount);
EXPECT_FALSE(context.memoryUpdated());
- EXPECT_FALSE(context.aborted);
+ EXPECT_FALSE(context.NPEThrown);
}
{
context.resetCallCount();
@@ -114,13 +114,13 @@
}
EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount);
EXPECT_FALSE(context.memoryUpdated());
- EXPECT_FALSE(context.aborted);
+ EXPECT_FALSE(context.NPEThrown);
}
{
context.resetCallCount();
{
ScopedArrayRO<TestType, false /* non null */> array(env, nullptr);
- EXPECT_TRUE(context.aborted);
+ EXPECT_TRUE(context.NPEThrown);
}
}
}
@@ -145,7 +145,7 @@
}
EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount);
EXPECT_FALSE(context.memoryUpdated());
- EXPECT_FALSE(context.aborted);
+ EXPECT_FALSE(context.NPEThrown);
}
{
context.resetCallCount();
@@ -159,7 +159,7 @@
}
EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount);
EXPECT_FALSE(context.memoryUpdated());
- EXPECT_FALSE(context.aborted);
+ EXPECT_FALSE(context.NPEThrown);
}
{
context.resetCallCount();
@@ -173,7 +173,7 @@
}
EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount);
EXPECT_FALSE(context.memoryUpdated());
- EXPECT_FALSE(context.aborted);
+ EXPECT_FALSE(context.NPEThrown);
}
}
@@ -197,7 +197,7 @@
}
EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount);
EXPECT_TRUE(context.memoryUpdated());
- EXPECT_FALSE(context.aborted);
+ EXPECT_FALSE(context.NPEThrown);
}
{
context.resetCallCount();
@@ -211,13 +211,13 @@
}
EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount);
EXPECT_TRUE(context.memoryUpdated());
- EXPECT_FALSE(context.aborted);
+ EXPECT_FALSE(context.NPEThrown);
}
{
context.resetCallCount();
{
ScopedArrayRW<TestType> array(env, nullptr);
- EXPECT_TRUE(context.aborted);
+ EXPECT_TRUE(context.NPEThrown);
}
}
}