You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jochen Theodorou (JIRA)" <ji...@apache.org> on 2017/03/21 20:50:41 UTC

[jira] [Commented] (GROOVY-8125) Upgrading to 2.4.6 breaks

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

Jochen Theodorou commented on GROOVY-8125:
------------------------------------------

some important things to know here:
  * myClass.something = a is not like a normal method call. This is setting a property of name something, which is backed by a method
  * the backing method is selected once for all usages of the property
  * in case of overloaded setters like above, it is random which of the two is taken. That means the behaviour was unstable before
  * you can replace myClass.something = a with myClass.setSomething(a) or other solutions
  * even for a method call Groovy does ignore the declaration type in a method call, only the runtime type counts.
  * for null the most general type is supposed to be used

So what I take away is that you did go from code, that works with luck to code that does not work at all anymore. You could use myClass.setSomething((A)a), or gate it through another class if you wanted. But in total I think the method resolution algorithm is actually not doing the right thing here. A is more general than B and should be taken instead of producing an error. 


> Upgrading to 2.4.6 breaks
> -------------------------
>
>                 Key: GROOVY-8125
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8125
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.6
>            Reporter: Saravanan Subiramaniam
>            Priority: Critical
>
> We recently upgraded to Groovy 2.4.6 version and running into Ambiguous method overloading for method error when setting null value. Reproducible test case:
> {code:java}
> interface A {}
> interface B extends A {}
> class MyClass {
>    public void setSomething(A a) { }
>    public void setSomething(B b) { }
> }
> def myClass = new MyClass()
> A a = null
> myClass.something = a
> {code}
> I'm not sure if this is similar to GROOVY-7481. Could you please suggest how to resolve this issue? Thanks.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)