eric-milles commented on code in PR #2572:
URL: https://github.com/apache/groovy/pull/2572#discussion_r3330581074


##########
src/main/java/groovy/lang/MetaClassImpl.java:
##########
@@ -998,7 +998,20 @@ private Object invokeMissingMethod(final Object instance, 
final String methodNam
             }
         }
 
-        throw original != null ? original : new 
MissingMethodExceptionNoStack(methodName, theClass, arguments, false);
+        // GROOVY-12046: MissingMethodException reports the metaclass theClass 
(a supertype)
+        //                 instead of the receiver's runtime class, breaking 
the GroovyObject.invokeMethod MOP fallback.
+        //
+        // The MOP fallback guard in 
IndyGuardsFiltersAndSignatures.invokeGroovyObjectInvoker checks
+        // `receiver.getClass() == e.getType()` before delegating to 
GroovyObject.invokeMethod.
+        // A per-instance metaclass may have theClass set to a supertype of 
the actual receiver (a
+        // common pattern in mocking frameworks), so we must use the 
receiver's runtime class as the
+        // exception type in that case; otherwise the guard fails and the 
fallback is silently skipped.
+        Class<?> type = theClass;
+        if (!(instance instanceof Class) && type != instance.getClass() && 
type.isAssignableFrom(instance.getClass())
+                && lookupObjectMetaClass(instance) == this) {
+            type = instance.getClass();
+        }

Review Comment:
   no need for all of this if original is non-null



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to