OSDN Git Service

Throw NoSuchMethodError if RegisterNatives fails.
authorElliott Hughes <enh@google.com>
Fri, 2 Aug 2013 00:29:14 +0000 (17:29 -0700)
committerElliott Hughes <enh@google.com>
Fri, 2 Aug 2013 00:29:14 +0000 (17:29 -0700)
Bug: 9963858
Change-Id: I5b3ce3d3dbdc949e69f3389e2df19bcca5648d7e

vm/Jni.cpp

index aa2f371..d91eb9c 100644 (file)
@@ -693,6 +693,11 @@ static void dumpCandidateMethods(ClassObject* clazz, const char* methodName, con
     dumpMethods(clazz->directMethods, clazz->directMethodCount, methodName);
 }
 
+static void throwNoSuchMethodError(ClassObject* c, const char* name, const char* sig, const char* kind) {
+    std::string msg(StringPrintf("no %s method \"%s.%s%s\"", kind, c->descriptor, name, sig));
+    dvmThrowNoSuchMethodError(msg.c_str());
+}
+
 /*
  * Register a method that uses JNI calling conventions.
  */
@@ -718,11 +723,13 @@ static bool dvmRegisterJNIMethod(ClassObject* clazz, const char* methodName,
     }
     if (method == NULL) {
         dumpCandidateMethods(clazz, methodName, signature);
+        throwNoSuchMethodError(clazz, methodName, signature, "static or non-static");
         return false;
     }
 
     if (!dvmIsNativeMethod(method)) {
         ALOGW("Unable to register: not native: %s.%s:%s", clazz->descriptor, methodName, signature);
+        throwNoSuchMethodError(clazz, methodName, signature, "native");
         return false;
     }