diff options
| author | 2013-12-19 14:59:00 -0800 | |
|---|---|---|
| committer | 2013-12-19 15:14:42 -0800 | |
| commit | e8c48db6bb507d7fa20c78481c58c23be0045f67 (patch) | |
| tree | ceac197a9d9f32609f845377e9fe87949bff5527 /runtime/jni_internal.cc | |
| parent | e40687d053b89c495b6fbeb7a766b01c9c7e039c (diff) | |
Fix NewLocalRef, NewGlobalRef to handle cleared weak globals.
We were not checking for null after decoding the reference, this
meant that we incorrectly created null weak global references instead
of returning null.
Issue: 63929
Change-Id: I9159682e6edad8f415ef8144fc13b9aedd2cceb4
Diffstat (limited to 'runtime/jni_internal.cc')
| -rw-r--r-- | runtime/jni_internal.cc | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc index 6690519eba..bbe5fda62f 100644 --- a/runtime/jni_internal.cc +++ b/runtime/jni_internal.cc @@ -844,13 +844,14 @@ class JNI { } static jobject NewGlobalRef(JNIEnv* env, jobject obj) { - if (obj == NULL) { - return NULL; - } ScopedObjectAccess soa(env); + Object* decoded_obj = soa.Decode<Object*>(obj); + // Check for null after decoding the object to handle cleared weak globals. + if (decoded_obj == nullptr) { + return nullptr; + } JavaVMExt* vm = soa.Vm(); IndirectReferenceTable& globals = vm->globals; - Object* decoded_obj = soa.Decode<Object*>(obj); WriterMutexLock mu(soa.Self(), vm->globals_lock); IndirectRef ref = globals.Add(IRT_FIRST_SEGMENT, decoded_obj); return reinterpret_cast<jobject>(ref); @@ -884,11 +885,13 @@ class JNI { } static jobject NewLocalRef(JNIEnv* env, jobject obj) { - if (obj == NULL) { - return NULL; - } ScopedObjectAccess soa(env); - return soa.AddLocalReference<jobject>(soa.Decode<Object*>(obj)); + mirror::Object* decoded_obj = soa.Decode<Object*>(obj); + // Check for null after decoding the object to handle cleared weak globals. + if (decoded_obj == nullptr) { + return nullptr; + } + return soa.AddLocalReference<jobject>(decoded_obj); } static void DeleteLocalRef(JNIEnv* env, jobject obj) { |