[
https://issues.apache.org/jira/browse/GROOVY-11196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17776363#comment-17776363
]
Eric Milles commented on GROOVY-11196:
--------------------------------------
I have looked into {{null}} -> {{NullObject}} and how it makes its way to the
"self" parameter of category/extension methods. I changed
{{Selector$MethodSelector#correctNullReceiver}} as follows:
{code:java}
/**
* Gives a replacement receiver for null. In the case of a null receiver
* we want to do the method invocation on the {@link NullObject}
instead.
*/
public void correctNullReceiver() {
if (args[0] == null && !(method instanceof NewInstanceMetaMethod)) {
handle = handle.bindTo(NullObject.getNullObject());
handle = MethodHandles.dropArguments(handle, 0,
targetType.parameterType(0));
if (LOG_ENABLED) LOG.info("binding NullObject receiver and
dropping old receiver");
}
}
{code}
There were no immediate problems seen making this change. We would also need
to alter {{NewInstanceMetaMethod#invoke}} I figure. And in terms of
{{tap}}/{{with}} I changed {{DgmConverter}}, replacing "ALOAD 1" and cast with
a check for {{NullObject}} (see attached).
Making this change, there were a number of failures for
"null.setMetaClass(...)" tests. So this change carries a bit more risk. I
still think it is a good avenue to pursue since null as the "self" argument is
how SC will invoke category methods.
> ambiguous method error for tap on null receiver
> -----------------------------------------------
>
> Key: GROOVY-11196
> URL: https://issues.apache.org/jira/browse/GROOVY-11196
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 3.0.19, 5.0.0-alpha-2, 4.0.15
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Major
> Fix For: 5.0.0-alpha-3
>
> Attachments: DgmConverter.java
>
>
> Consider the following:
> {code:groovy}
> abstract class A {
> abstract m(List list, String string)
> }
> class C extends A {
> @Override m(List list, String string) {
> print 'works'
> }
> }
> Object test(List list, String string) {
> list.tap {
> new C().m(it,string)
> }
> }
> test(null,"")
> {code}
> "list.tap{" propagates {{NullObject}} into closure and then method selection
> falls down.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)