[
https://issues.apache.org/jira/browse/GROOVY-10859?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17642725#comment-17642725
]
Marcin Erdmann edited comment on GROOVY-10859 at 12/2/22 11:35 PM:
-------------------------------------------------------------------
Not using a method reference but instead using a closure literal which invokes
the referred method in the body is also a valid workaround which is more
convenient in my case.
bq. I think the extension method "static <T> Stream<T> stream(T self)" may be
getting in the way.
That would explain the failure because {{static <T> Stream<T> stream(T self)}}
returns a stream of self an I'm getting a single element iterator which
contains a class object. So this is more specific that any method on {{List}}
as suggested in the issue title, it has to be a zero arg method on {{List}}
that also has an extension method of the same name defined on {{Object}}.
was (Author: erdi):
Not using a method reference but instead using a closure literal which invokes
the referred method in the body is also a valid workaround which is more
convenient in my case.
bq. I think the extension method "static <T> Stream<T> stream(T self)" may be
getting in the way.
That would explain the failure because {{static <T> Stream<T> stream(T self)}}
returns a stream of self an I'm getting a single element iterator which
contains a class object. So this is more specific that any method on {{List}}
as suggested in the issue title, it has to be a zero arg method on {{List}}
that also has an extension method of the same name defined on `Object`.
> Regression in invoking method references to methods from List class when
> called on empty lists
> ----------------------------------------------------------------------------------------------
>
> Key: GROOVY-10859
> URL: https://issues.apache.org/jira/browse/GROOVY-10859
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.0
> Reporter: Marcin Erdmann
> Assignee: Eric Milles
> Priority: Major
>
> While migrating from Groovy 3 to Groovy 4 I have uncovered a regression in
> how method references to methods on {{List}} are invoked when called on empty
> lists. The following test case passes on Groovy 3:
> {code:java}
> def "method references from List class are invoked correctly on empty
> lists"() {
> given:
> def streamOfEmptyCollections = [[]].stream()
> when:
> def flattened =
> streamOfEmptyCollections.flatMap(List::stream).toList()
> then:
> flattened == []
> }
> {code}
> But on Groovy 4 it fails with the following error:
> {noformat}
> Condition not satisfied:
> flattened == []
> | |
> | false
> [interface java.util.List]
> {noformat}
> I believe that this regression was introduced by [this change to
> {{groovy.lang.MetaClassImpl.invokeMethodClosure()}}|https://github.com/apache/groovy/commit/22e5f3bb1823041f9b0445d8e1de0c02dfa87fd1#diff-c28986077bdc1a71b46273a2f3596d89d4608fadc5843b56ec0bc25894e19652R1084]
> which was part of the fix for GROOVY-10057.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)