You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Rachel Greenham (Jira)" <ji...@apache.org> on 2022/11/24 18:04:00 UTC

[jira] [Created] (GROOVY-10856) MethodSelectionException when calling respondsTo()

Rachel Greenham created GROOVY-10856:
----------------------------------------

             Summary: MethodSelectionException when calling respondsTo()
                 Key: GROOVY-10856
                 URL: https://issues.apache.org/jira/browse/GROOVY-10856
             Project: Groovy
          Issue Type: Bug
          Components: Documentation
    Affects Versions: 4.0.6
         Environment: Seen in Groovy 4.0.6 on Linux x64 with java 17.0.5 and MacOS aarch64 in Java 19.0.1. I don't think any of that is significant. 😀
            Reporter: Rachel Greenham
         Attachments: responds-to-issue.groovy

if you have a method which takes certain parameters, and annotate it {{{}@NamedVariant{}}}, and then try a respondsTo with a null, or an empty array, you get this exception, listing both the methods that are there, rather than the expected groovy-falsehood (empty list) for no matching methods.

This is related to 
 # GROOVY-8248
 # GROOVY-8660

but is different in scope because this is about the behaviour, specifically, of MetaObjectProtocol::respondsTo, which states clearly in the documentation that:
{quote}This method is "safe" in that it will always return a value and never throw an exception
{quote}
... which turns out not to be true, and should be. The behaviour may not be wrong for the calls described in the other two bugs, but MetaObjectProtocol::respondsTo, specifically, should be catching this, and returning, as promised, a groovy falsehood. (probably an empty list, which is correct as neither of the methods match.)

Attached, a small script demonstrating this, which shows the problem clearly if simply run in groovy console.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)