ART: Tolerate shallow call stack in VMStack_getCallingClassLoader
When the call stack does not have the three methods we expect,
the visitor will return a nullptr value.
Add a test to JniTest (and refactor the test a little for code reuse).
Bug: 16867274
(cherry picked from commit 61bf6a1c80bf797af5d7911ff71fc367fdb36742)
Change-Id: I5fb8f91f372a41e0bc11ef9f70640834591afa53
diff --git a/runtime/native/dalvik_system_VMStack.cc b/runtime/native/dalvik_system_VMStack.cc
index 5f718ba..047e9f6 100644
--- a/runtime/native/dalvik_system_VMStack.cc
+++ b/runtime/native/dalvik_system_VMStack.cc
@@ -76,6 +76,10 @@
ScopedFastNativeObjectAccess soa(env);
NthCallerVisitor visitor(soa.Self(), 2);
visitor.WalkStack();
+ if (UNLIKELY(visitor.caller == nullptr)) {
+ // The caller is an attached native thread.
+ return nullptr;
+ }
return soa.AddLocalReference<jobject>(visitor.caller->GetDeclaringClass()->GetClassLoader());
}