Skip to content
Permalink
Browse files
GROOVY-10635: Method references not working for record components in …
…dynamic code
  • Loading branch information
paulk-asert committed May 23, 2022
1 parent 2691fb0 commit 4cb6a0efc8e15535cca06eb3a72fe6a5c9f02e3f
Showing 2 changed files with 11 additions and 1 deletion.
@@ -1022,7 +1022,7 @@ private Object invokeMethodClosure(Object object, Object[] arguments) {
try {
return ownerMetaClass.invokeMethod(ownerClass, owner, methodName, arguments, false, false);

} catch (MissingMethodExceptionNoStack | InvokerInvocationException e) {
} catch (MissingMethodExceptionNoStack | InvokerInvocationException | IllegalArgumentException e) {
if (ownerIsClass) {
if (MethodClosure.NEW.equals(methodName)) { // CONSTRUCTOR REFERENCE
if (!ownerClass.isArray()) {
@@ -709,4 +709,14 @@ final class MethodReferenceTest {
'''
assert err =~ /The argument is a method reference, but the parameter type is not a functional interface/
}

@Test // GROOVY-10635
void testRecordComponentMethodReference() {
assertScript shell, '''
record Bar(String name) { }
def bars = [new Bar(name: 'A'), new Bar(name: 'B')]
assert bars.stream().map(Bar::name).map(String::toLowerCase).toList() == ['a', 'b']
'''
}
}

0 comments on commit 4cb6a0e

Please sign in to comment.