/* *Wecanalsosafelyassumetheconstructorisn'tassociated *withaninterface,array,orprimitiveclass.Ifthisiscomingfrom *native,itisOKtoavoidaccesscheckssinceJNIdoesnotenforcethem.
*/ static jobject Constructor_newInstance0(JNIEnv* env, jobject javaMethod, jobjectArray javaArgs) {
ScopedFastNativeObjectAccess soa(env);
ObjPtr<mirror::Constructor> m = soa.Decode<mirror::Constructor>(javaMethod);
ArtMethod* constructor_art_method = m->GetArtMethod(); // newInstance0 isn't called for serialized constructors. See newInstance implementation in // java/lang/reflect/Constructor.java in libcore.
DCHECK_NE(constructor_art_method, nullptr);
StackHandleScope<1> hs(soa.Self());
Handle<mirror::Class> c(hs.NewHandle(m->GetDeclaringClass())); if (UNLIKELY(c->IsAbstract())) {
soa.Self()->ThrowNewExceptionF("Ljava/lang/InstantiationException;", "Can't instantiate %s %s",
c->IsInterface() ? "interface" : "abstract class",
c->PrettyDescriptor().c_str()); return nullptr;
} // Verify that we can access the class. if (!m->IsAccessible() && !c->IsPublic()) { // Go 2 frames back, this method is always called from newInstance0, which is called from // Constructor.newInstance(Object... args).
ObjPtr<mirror::Class> caller = GetCallingClass(soa.Self(), 2); // If caller is null, then we called from JNI, just avoid the check since JNI avoids most // access checks anyways. TODO: Investigate if this the correct behavior. if (caller != nullptr && !caller->CanAccess(c.Get())) { if (c->PrettyDescriptor() == "dalvik.system.DexPathList$Element") { // b/20699073.
LOG(WARNING) << "The dalvik.system.DexPathList$Element constructor is not accessible by " "default. This is a temporary workaround for backwards compatibility " "with class-loader hacks. Please update your application.";
} else {
soa.Self()->ThrowNewExceptionF( "Ljava/lang/IllegalAccessException;", "%s is not accessible from %s",
c->PrettyClass().c_str(),
caller->PrettyClass().c_str()); return nullptr;
}
}
} if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(soa.Self(), c, true, true)) {
DCHECK(soa.Self()->IsExceptionPending()); return nullptr;
} bool movable = true; if (!kMovingClasses && c->IsClassClass()) {
movable = false;
}
// String constructor is replaced by a StringFactory method in InvokeMethod. if (UNLIKELY(c->IsStringClass())) { return InvokeMethod<kRuntimePointerSize>(soa, javaMethod, nullptr, javaArgs, 2);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.