diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-12-09 02:18:36 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-12-09 02:18:36 +0000 |
| commit | d70e6c1fca13abae80c4e1d888d93405e5ae54d4 (patch) | |
| tree | f3bf9b2a4c8f30e7ecd8606fc260e30b5b16a8b4 | |
| parent | 3204e23c0641141e4a039c52a9478ce307c9435d (diff) | |
| parent | db56e11f9b443648d09b0b3c3fc27a783be1774c (diff) | |
| download | platform_libnativehelper-d70e6c1fca13abae80c4e1d888d93405e5ae54d4.tar.gz platform_libnativehelper-d70e6c1fca13abae80c4e1d888d93405e5ae54d4.tar.bz2 platform_libnativehelper-d70e6c1fca13abae80c4e1d888d93405e5ae54d4.zip | |
Merge "Switch fatalError to NPE"
| -rw-r--r-- | header_only_include/nativehelper/scoped_primitive_array.h | 8 | ||||
| -rw-r--r-- | tests/scoped_primitive_array_test.cpp | 26 |
2 files changed, 17 insertions, 17 deletions
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 @@ public: 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 @@ public: 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 @@ public: 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 @@ struct TestContext { 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 @@ public: 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 @@ TEST(ScopedPrimitiveArrayTest, testNonNullArray) { } EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount); EXPECT_FALSE(context.memoryUpdated()); - EXPECT_FALSE(context.aborted); + EXPECT_FALSE(context.NPEThrown); } { context.resetCallCount(); @@ -114,13 +114,13 @@ TEST(ScopedPrimitiveArrayTest, testNonNullArray) { } 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 @@ TEST(ScopedPrimitiveArrayTest, testNullableArray) { } EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount); EXPECT_FALSE(context.memoryUpdated()); - EXPECT_FALSE(context.aborted); + EXPECT_FALSE(context.NPEThrown); } { context.resetCallCount(); @@ -159,7 +159,7 @@ TEST(ScopedPrimitiveArrayTest, testNullableArray) { } EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount); EXPECT_FALSE(context.memoryUpdated()); - EXPECT_FALSE(context.aborted); + EXPECT_FALSE(context.NPEThrown); } { context.resetCallCount(); @@ -173,7 +173,7 @@ TEST(ScopedPrimitiveArrayTest, testNullableArray) { } EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount); EXPECT_FALSE(context.memoryUpdated()); - EXPECT_FALSE(context.aborted); + EXPECT_FALSE(context.NPEThrown); } } @@ -197,7 +197,7 @@ TEST(ScopedPrimitiveArrayTest, testArrayRW) { } EXPECT_EQ(context.getArrayElementsCallCount, context.releaseArrayElementsCallCount); EXPECT_TRUE(context.memoryUpdated()); - EXPECT_FALSE(context.aborted); + EXPECT_FALSE(context.NPEThrown); } { context.resetCallCount(); @@ -211,13 +211,13 @@ TEST(ScopedPrimitiveArrayTest, testArrayRW) { } 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); } } } |
