You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Richard Eckart de Castilho (Jira)" <ji...@apache.org> on 2025/08/30 21:37:00 UTC

[jira] [Commented] (LANG-1597) Invocation fails because matching varargs method found but then discarded

    [ https://issues.apache.org/jira/browse/LANG-1597?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18017223#comment-18017223 ] 

Richard Eckart de Castilho commented on LANG-1597:
--------------------------------------------------

Thanks for fixing!

I'm afraid though that after 5 years, I don't have the slightest clue anymore how to reproduce that and in which particular project I have encountered the problem. Should I by chance come across it, I'll let you know.

> Invocation fails because matching varargs method found but then discarded
> -------------------------------------------------------------------------
>
>                 Key: LANG-1597
>                 URL: https://issues.apache.org/jira/browse/LANG-1597
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.reflect.*
>    Affects Versions: 3.11
>            Reporter: Richard Eckart de Castilho
>            Priority: Major
>             Fix For: 3.19.0
>
>
> {{getMatchingAccessibleMethod(Class<?>, String, Class<?>...)}} is able to find proper match for a method to call but then discards it.
> Consider the situation you have a varargs method like {{Baz.foo(X... X)}}. We call {{getMatchingAccessibleMethod(Baz.class, "foo", z}} where {{z instance of Z extends Y extends X}}. {{getMatchingAccessibleMethod}} finds {{foo}} as the candidate, but then discards it because for varargs, it requires either the argument is directly is of type X or that the supertype of the argument X. It does not properly check the entire inheritance hierarchy in this code (3.11):
> {code}
>         if (bestMatch != null && bestMatch.isVarArgs() && bestMatch.getParameterTypes().length > 0 && parameterTypes.length > 0) {
>             final Class<?>[] methodParameterTypes = bestMatch.getParameterTypes();
>             final Class<?> methodParameterComponentType = methodParameterTypes[methodParameterTypes.length - 1].getComponentType();
>             final String methodParameterComponentTypeName = ClassUtils.primitiveToWrapper(methodParameterComponentType).getName();
>             final Class<?> lastParameterType = parameterTypes[parameterTypes.length - 1];
>             final String parameterTypeName = (lastParameterType==null) ? null : lastParameterType.getName();
>             final String parameterTypeSuperClassName = (lastParameterType==null) ? null : lastParameterType.getSuperclass().getName();
>             if (parameterTypeName!= null && parameterTypeSuperClassName != null && !methodParameterComponentTypeName.equals(parameterTypeName)
>                     && !methodParameterComponentTypeName.equals(parameterTypeSuperClassName)) {
>                 return null;
>             }
>         }
> {code}



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