From 20b7a9b8aeaf76fc8f3248f211489fd00af73170 Mon Sep 17 00:00:00 2001 From: Alex Light Date: Tue, 26 Nov 2019 10:47:43 -0800 Subject: Fix Missing ReflectiveHandleScope in Class_newInstance The Class_newInstance method (the native implementation of the j.l.Class.newInstance function) incorrectly held an ArtMethod* for the constructor over a suspend point. This could lead to an obsolete method being called or (worst case) CHECK failures due to not finishing the initialization of the class if it's made obsolete. Test: ./test/run-test --host 2001 Bug: 145197371 Bug: 134162467 Change-Id: I7813977bfdd17165da810a1705197654eef024a1 --- runtime/native/java_lang_Class.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'runtime/native/java_lang_Class.cc') diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 49e37fe3e6..da87713d54 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -48,6 +48,7 @@ #include "nth_caller_visitor.h" #include "obj_ptr-inl.h" #include "reflection.h" +#include "reflective_handle_scope-inl.h" #include "scoped_fast_native_object_access-inl.h" #include "scoped_thread_state_change-inl.h" #include "well_known_classes.h" @@ -900,11 +901,10 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) { return nullptr; } } - ArtMethod* constructor = klass->GetDeclaredConstructor( - soa.Self(), - ScopedNullHandle>(), - kRuntimePointerSize); - if (UNLIKELY(constructor == nullptr) || ShouldDenyAccessToMember(constructor, soa.Self())) { + StackArtMethodHandleScope<1> mhs(soa.Self()); + ReflectiveHandle constructor(mhs.NewMethodHandle(klass->GetDeclaredConstructor( + soa.Self(), ScopedNullHandle>(), kRuntimePointerSize))); + if (UNLIKELY(constructor == nullptr) || ShouldDenyAccessToMember(constructor.Get(), soa.Self())) { soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;", "%s has no zero argument constructor", klass->PrettyClass().c_str()); -- cgit v1.2.3-59-g8ed1b