From ba5105c3742b5083f8fe4488dbfd6d607141c9f9 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 2 Jun 2009 18:55:12 -0600 Subject: [PATCH] throw NoSuchMethodError in resolveMethod if method not found --- src/compile.cpp | 44 ++++++++++---------------------------------- src/machine.cpp | 13 +++++++++++-- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/compile.cpp b/src/compile.cpp index 8b542d1874..6c04a03721 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -5477,15 +5477,11 @@ callContinuation(MyThread* t, object continuation, object result, if (rewindMethod(t) == 0) { PROTECT(t, nextContinuation); - - const char* const className = "avian/Continuations"; - const char* const methodName = "rewind"; - const char* const methodSpec - = "(Ljava/lang/Runnable;Lavian/Callback;Ljava/lang/Object;" - "Ljava/lang/Throwable;)V"; object method = resolveMethod - (t, className, methodName, methodSpec); + (t, "avian/Continuations", "rewind", + "(Ljava/lang/Runnable;Lavian/Callback;Ljava/lang/Object;" + "Ljava/lang/Throwable;)V"); if (method) { rewindMethod(t) = method; @@ -5496,11 +5492,6 @@ callContinuation(MyThread* t, object continuation, object result, action = Throw; } } else { - object message = makeString - (t, "%s %s not found in %s", - methodName, methodSpec, className); - - t->exception = makeNoSuchMethodError(t, message); action = Throw; } } @@ -5558,21 +5549,13 @@ callWithCurrentContinuation(MyThread* t, object receiver) { PROTECT(t, receiver); if (receiveMethod(t) == 0) { - const char* const className = "avian/CallbackReceiver"; - const char* const methodName = "receive"; - const char* const methodSpec = "(Lavian/Callback;)Ljava/lang/Object;"; - - object m = resolveMethod(t, className, methodName, methodSpec); + object m = resolveMethod + (t, "avian/CallbackReceiver", "receive", + "(Lavian/Callback;)Ljava/lang/Object;"); if (m) { receiveMethod(t) = m; - } else { - object message = makeString - (t, "%s %s not found in %s", methodName, methodSpec, className); - t->exception = makeNoSuchMethodError(t, message); - } - if (LIKELY(t->exception == 0)) { object continuationClass = arrayBody (t, t->m->types, Machine::ContinuationType); @@ -5614,21 +5597,14 @@ dynamicWind(MyThread* t, object before, object thunk, object after) PROTECT(t, after); if (windMethod(t) == 0) { - const char* const className = "avian/Continuations"; - const char* const methodName = "wind"; - const char* const methodSpec - = "(Ljava/lang/Runnable;Ljava/util/concurrent/Callable;" - "Ljava/lang/Runnable;)Lavian/Continuations$UnwindResult;"; - - object method = resolveMethod(t, className, methodName, methodSpec); + object method = resolveMethod + (t, "avian/Continuations", "wind", + "(Ljava/lang/Runnable;Ljava/util/concurrent/Callable;" + "Ljava/lang/Runnable;)Lavian/Continuations$UnwindResult;"); if (method) { windMethod(t) = method; compile(t, ::codeAllocator(t), 0, method); - } else { - object message = makeString - (t, "%s %s not found in %s", methodName, methodSpec, className); - t->exception = makeNoSuchMethodError(t, message); } } diff --git a/src/machine.cpp b/src/machine.cpp index c0ee2be304..9c8e167380 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2521,8 +2521,17 @@ resolveMethod(Thread* t, const char* className, const char* methodName, object spec = makeByteArray(t, methodSpec); object reference = makeReference(t, class_, name, spec); - return findMethodInClass(t, class_, referenceName(t, reference), - referenceSpec(t, reference)); + object method = findMethodInClass(t, class_, referenceName(t, reference), + referenceSpec(t, reference)); + + if (t->exception == 0 and method == 0) { + object message = makeString + (t, "%s %s not found in %s", methodName, methodSpec, className); + + t->exception = makeNoSuchMethodError(t, message); + } else { + return method; + } } return 0;