diff options
| author | 2019-11-26 10:47:43 -0800 | |
|---|---|---|
| committer | 2019-12-02 18:34:20 +0000 | |
| commit | 20b7a9b8aeaf76fc8f3248f211489fd00af73170 (patch) | |
| tree | 33a09412c220b5bfc9935a84fabd92a39aa4c35f /runtime/native/java_lang_Class.cc | |
| parent | c6ca1170904c9f5bbdf0ee5b12d6d4cb093739fc (diff) | |
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
Diffstat (limited to 'runtime/native/java_lang_Class.cc')
| -rw-r--r-- | runtime/native/java_lang_Class.cc | 10 |
1 files changed, 5 insertions, 5 deletions
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<mirror::ObjectArray<mirror::Class>>(), - kRuntimePointerSize); - if (UNLIKELY(constructor == nullptr) || ShouldDenyAccessToMember(constructor, soa.Self())) { + StackArtMethodHandleScope<1> mhs(soa.Self()); + ReflectiveHandle<ArtMethod> constructor(mhs.NewMethodHandle(klass->GetDeclaredConstructor( + soa.Self(), ScopedNullHandle<mirror::ObjectArray<mirror::Class>>(), 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()); |