Put a handle on the String object.
Otherwise, a GC could occur in the loop below, and the String
be moved (note that there was already one for the Class object to
protect for that same problem).
bug:27561834
Change-Id: I5ad0e0cac148bc6e028d05eff67f18932ec46ea8
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc
index 6b7ca40..0624da3 100644
--- a/runtime/native/java_lang_Class.cc
+++ b/runtime/native/java_lang_Class.cc
@@ -238,12 +238,13 @@
DCHECK(name != nullptr);
DCHECK(self != nullptr);
- StackHandleScope<1> hs(self);
+ StackHandleScope<2> hs(self);
MutableHandle<mirror::Class> h_clazz(hs.NewHandle(clazz));
+ Handle<mirror::String> h_name(hs.NewHandle(name));
// We search the current class, its direct interfaces then its superclass.
while (h_clazz.Get() != nullptr) {
- mirror::Field* result = GetDeclaredField(self, h_clazz.Get(), name);
+ mirror::Field* result = GetDeclaredField(self, h_clazz.Get(), h_name.Get());
if ((result != nullptr) && (result->GetAccessFlags() & kAccPublic)) {
return result;
} else if (UNLIKELY(self->IsExceptionPending())) {
@@ -258,7 +259,7 @@
self->AssertPendingException();
return nullptr;
}
- result = GetPublicFieldRecursive(self, iface, name);
+ result = GetPublicFieldRecursive(self, iface, h_name.Get());
if (result != nullptr) {
DCHECK(result->GetAccessFlags() & kAccPublic);
return result;