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

Eric Milles commented on GROOVY-10214:
--------------------------------------

I think the source of this issue comes from 
{{MetaClassImpl#findCategoryMethod}}.  In the case where there are multiple 
category methods that satisfy assignability of self type, sorting is performed 
and this compares the self types to each other.  I think it should be comparing 
against the self type argument to pick the best match.  For me, the Double 
method is selected.

{code:java}
    private static CategoryMethod findCategoryMethod(final String name, final 
Class<?> sender, final java.util.function.Predicate<CachedClass[]> paramFilter) 
{
        List<CategoryMethod> categoryMethods = 
GroovyCategorySupport.getCategoryMethods(name);
        if (categoryMethods != null) {
            return categoryMethods.stream().filter(categoryMethod ->
                categoryMethod.getDeclaringClass().isAssignableFrom(sender) && 
paramFilter.test(categoryMethod.getParameterTypes())
            ).sorted().findFirst().orElse(null);
        }
        return null;
    }
{code}

> Update from Groovy 3.0.8 to 3.0.9 breaks category class
> -------------------------------------------------------
>
>                 Key: GROOVY-10214
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10214
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.9, 4.0.0
>         Environment: java --version
> openjdk 16.0.2 2021-07-20
> OpenJDK Runtime Environment Temurin-16.0.2+7 (build 16.0.2+7)
> OpenJDK 64-Bit Server VM Temurin-16.0.2+7 (build 16.0.2+7, mixed mode, 
> sharing)
>            Reporter: Alexander Veit
>            Priority: Major
>
> We have a category class as part of our product's Groovy API that breaks 
> after the update from Groovy 3.0.8 (indy) to 3.0.9 (indy).
> Scripts that call the category class with Integer of Long arguments throw an 
> exception. E.g.
> {code:java}
> use (org.example.Convert)
> {
>       assert '1234' == 1234.canonicalLexicalRepresentation
> }
> {code}
> throws
> {noformat}
> java.lang.IllegalArgumentException: argument type mismatch
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
>       at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.base/java.lang.reflect.Method.invoke(Method.java:567)
>       at 
> org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:54)
>       at 
> org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:54)
>       at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
>       at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1956)
>       at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3843)
>       at 
> org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:199)
>       at 
> org.codehaus.groovy.runtime.callsite.PojoMetaClassGetPropertySite.getProperty(PojoMetaClassGetPropertySite.java:36)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:329)
>       at 
> org.example.test.testInteger$_run_closure1.doCall(testInteger.groovy:5)
>       at org.example.test.testInteger$_run_closure1.doCall(testInteger.groovy)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
>       at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.base/java.lang.reflect.Method.invoke(Method.java:567)
>       at 
> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
>       at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
>       at 
> org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:274)
>       at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035)
>       at groovy.lang.Closure.call(Closure.java:412)
>       at groovy.lang.Closure.call(Closure.java:406)
>       at 
> org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:123)
>       at 
> org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.access$300(GroovyCategorySupport.java:72)
>       at 
> org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:258)
>       at 
> org.codehaus.groovy.runtime.DefaultGroovyMethods.use(DefaultGroovyMethods.java:568)
>       at org.codehaus.groovy.runtime.dgm$880.invoke(Unknown Source)
>       at 
> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:226)
>       at 
> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:61)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:194)
>       at org.example.test.testInteger.run(testInteger.groovy:3)
>       at groovy.lang.GroovyShell.evaluate(GroovyShell.java:427)
>       at groovy.lang.GroovyShell.evaluate(GroovyShell.java:470)
> {noformat}
> The categoy class is implemented in Java and looks something like
> {code:java}
> public final class Convert
> {
>       private Convert()
>       {
>       }
>       public static final String 
> getCanonicalLexicalRepresentation(CharSequence p_chseq)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(Boolean 
> p_bool)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(Byte 
> p_byte)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(Short 
> p_short)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(Integer 
> p_int)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(Long p_lng)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(Float 
> p_flt)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(Double 
> p_dbl)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(BigDecimal 
> p_decimal, boolean p_bInteger)
>       {
>               return "foo";
>       }
>       public static final String 
> getCanonicalLexicalRepresentationDateTime(Date p_dt)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentationDate(Date 
> p_dt)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentationTime(Date 
> p_dt)
>       {
>               return "foo";
>       }
>       public static final String getCanonicalLexicalRepresentation(QName 
> p_qnm)
>       {
>               return "foo";
>       }
>       public static String getCanonicalLexicalRepresentation(Object p_value, 
> QName p_qnmType)
>       {
>               return "foo";
>       }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to