Skip to content

GROOVY-12591: create the GString adapter of a method reference without ACC_FINAL in an interface - #3116

Closed
codeconsole wants to merge 1 commit into
apache:masterfrom
codeconsole:sc-gstring-adapter-interface
Closed

codeconsole wants to merge 1 commit into
apache:masterfrom
codeconsole:sc-gstring-adapter-interface

Conversation

@codeconsole

Copy link
Copy Markdown
Contributor

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.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.

…t ACC_FINAL in an interface

The JVM rejects ACC_FINAL on any method of an interface (JVMS 4.6), so an
interface with a statically compiled method reference taking a String
failed to load with ClassFormatError. The other helper methods of method
references already leave it out there.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.1056%. Comparing base (a4b28fe) to head (66edd8d).
⚠️ Report is 58 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #3116        +/-   ##
==================================================
+ Coverage     73.7672%   74.1056%   +0.3385%     
- Complexity      42748      43593       +845     
==================================================
  Files            1678       1692        +14     
  Lines          147464     149237      +1773     
  Branches        27899      28282       +383     
==================================================
+ Hits           108780     110593      +1813     
+ Misses          28523      28473        -50     
- Partials        10161      10171        +10     
Files with missing lines Coverage Δ
...sc/StaticTypesMethodReferenceExpressionWriter.java 89.3182% <100.0000%> (+0.2425%) ⬆️

... and 38 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Oct 31, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 66edd8d
▶️ Tests: 109451 executed
⚪️ Checks: 26/26 completed


Learn more about TestLens at testlens.app/docs.

@codeconsole

Copy link
Copy Markdown
Contributor Author

Closing: @paulk-asert made the same change on master in b76142b (GROOVY-12536), together with the update to the GROOVY-12488 interface test, so master is green again and this PR has nothing left to add. Thanks, Paul.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants