summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2014-12-22 17:43:36 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-12-22 17:43:37 +0000
commit508d2665febbb06c853bfab131c4dc7164fffabb (patch)
tree31e5dbc57686d3bbf0d78b49ecbe454acfee7867 /runtime
parent094368ae2fa7a4eeaafb44f6018e498c1054af60 (diff)
parenta87630724ef4f8760684fa69c8ecc685735aff88 (diff)
downloadart-508d2665febbb06c853bfab131c4dc7164fffabb.zip
art-508d2665febbb06c853bfab131c4dc7164fffabb.tar.gz
art-508d2665febbb06c853bfab131c4dc7164fffabb.tar.bz2
Merge "ART: Do not JNI abort on nullptr GetObjectRefType"
Diffstat (limited to 'runtime')
-rw-r--r--runtime/jni_internal.cc8
-rw-r--r--runtime/jni_internal_test.cc16
2 files changed, 15 insertions, 9 deletions
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index 4797e69..37ad46e 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -2256,8 +2256,10 @@ class JNI {
java_buffer, WellKnownClasses::java_nio_DirectByteBuffer_capacity));
}
- static jobjectRefType GetObjectRefType(JNIEnv* env, jobject java_object) {
- CHECK_NON_NULL_ARGUMENT_RETURN(java_object, JNIInvalidRefType);
+ static jobjectRefType GetObjectRefType(JNIEnv* env ATTRIBUTE_UNUSED, jobject java_object) {
+ if (java_object == nullptr) {
+ return JNIInvalidRefType;
+ }
// Do we definitely know what kind of reference this is?
IndirectRef ref = reinterpret_cast<IndirectRef>(java_object);
@@ -2274,7 +2276,7 @@ class JNI {
return JNILocalRefType;
}
LOG(FATAL) << "IndirectRefKind[" << kind << "]";
- return JNIInvalidRefType;
+ UNREACHABLE();
}
private:
diff --git a/runtime/jni_internal_test.cc b/runtime/jni_internal_test.cc
index 045fe2f..8e32968 100644
--- a/runtime/jni_internal_test.cc
+++ b/runtime/jni_internal_test.cc
@@ -1300,16 +1300,20 @@ TEST_F(JniInternalTest, GetObjectRefType) {
jweak weak_global = env_->NewWeakGlobalRef(local);
EXPECT_EQ(JNIWeakGlobalRefType, env_->GetObjectRefType(weak_global));
- CheckJniAbortCatcher jni_abort_catcher;
- jobject invalid = reinterpret_cast<jobject>(this);
- EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(invalid));
- jni_abort_catcher.Check("use of invalid jobject");
+ {
+ CheckJniAbortCatcher jni_abort_catcher;
+ jobject invalid = reinterpret_cast<jobject>(this);
+ EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(invalid));
+ jni_abort_catcher.Check("use of invalid jobject");
+ }
// TODO: invoke a native method and test that its arguments are considered local references.
- // Null as object should fail.
+ // Null as pointer should not fail and return invalid-ref. b/18820997
EXPECT_EQ(JNIInvalidRefType, env_->GetObjectRefType(nullptr));
- jni_abort_catcher.Check("java_object == null");
+
+ // TODO: Null as reference should return the original type.
+ // This requires running a GC so a non-null object gets freed.
}
TEST_F(JniInternalTest, StaleWeakGlobal) {