[
https://issues.apache.org/jira/browse/GROOVY-12591?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18135500#comment-18135500
]
ASF GitHub Bot commented on GROOVY-12591:
-----------------------------------------
codeconsole opened a new pull request, #3116:
URL: https://github.com/apache/groovy/pull/3116
Master fails to load an interface with a statically compiled method
reference that takes a `String`, and
`MethodReferenceTest.testMethodReferencesInStaticAndDefaultMethodsOfInterface`
fails on every JDK since #3056 was merged:
```groovy
@groovy.transform.CompileStatic
interface I {
static java.util.function.Function<String, String> f() { String::trim }
}
I.f() // ClassFormatError: Method gstring$String$trim$1 in class I has
illegal modifiers: 0x101A
```
GROOVY-12536 (#3056) adds a synthetic adapter that converts a `GString`
argument to `String`, created `private static final`. The JVM rejects
`ACC_FINAL` on an interface method (JVMS 4.6). The other helper methods of
method references leave it out in interfaces since GROOVY-12488 (#3022); the
adapter now does the same.
`testMethodReferencesInStaticAndDefaultMethodsOfInterface` also lists the
helper methods of the interface, and now expects the `gstring` adapters there.
## Tests
`MethodReferenceTest.testMethodReferenceTakingStringInInterface` (a
`GString` element through `String::length` in a static interface method and
`String::trim` in a default method) and
`testMethodReferencesInStaticAndDefaultMethodsOfInterface` fail without the
change; `MethodReferenceTest` passes. The Checkstyle and CodeNarc gates pass.
> SC: a method reference in an interface fails to load with ClassFormatError:
> the GString adapter method is final
> ---------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12591
> URL: https://issues.apache.org/jira/browse/GROOVY-12591
> Project: Groovy
> Issue Type: Bug
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> On master, a statically compiled method or constructor reference with a
> String parameter inside an interface makes the interface fail to load:
> {code:groovy}
> @groovy.transform.CompileStatic
> interface I {
> static java.util.function.Function<String, String> f() { String::trim }
> }
> I.f()
> {code}
> {noformat}
> java.lang.ClassFormatError: Method gstring$String$trim$1 in class I has
> illegal modifiers: 0x101A
> {noformat}
> GROOVY-12536 adds a synthetic adapter method that converts a GString argument
> to String, and creates it {{private static final}}. The JVM rejects
> {{ACC_FINAL}} on an interface method (JVMS 4.6). The other helper methods of
> method references leave out {{ACC_FINAL}} in interfaces since GROOVY-12488.
> No test of GROOVY-12536 had a method reference in an interface;
> {{MethodReferenceTest.testMethodReferencesInStaticAndDefaultMethodsOfInterface}}
> from GROOVY-12488 has, and fails on master since both were merged, on every
> JDK.
> Affects master only (7.0.0-SNAPSHOT); no release has both changes.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)