From 4cb6a0efc8e15535cca06eb3a72fe6a5c9f02e3f Mon Sep 17 00:00:00 2001 From: Paul King Date: Mon, 23 May 2022 22:43:17 +1000 Subject: [PATCH] GROOVY-10635: Method references not working for record components in dynamic code --- src/main/java/groovy/lang/MetaClassImpl.java | 2 +- .../groovy/transform/stc/MethodReferenceTest.groovy | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java index c57b0331c06..947007fe026 100644 --- a/src/main/java/groovy/lang/MetaClassImpl.java +++ b/src/main/java/groovy/lang/MetaClassImpl.java @@ -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()) { diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy index 0935f6f110c..a3f401a1f40 100644 --- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy +++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy @@ -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'] + ''' + } }