Skip to content

GROOVY-12519: resolve super.name() and super.name to a static member the class hides - #3045

Merged
daniellansun merged 18 commits into
apache:masterfrom
codeconsole:super-hidden-static-member
Nov 22, 2026
Merged

daniellansun merged 18 commits into
apache:masterfrom
codeconsole:super-hidden-static-member

Conversation

@codeconsole

@codeconsole codeconsole commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

When a class declares a static method or property with the same signature as its superclass, super.sm() threw MissingMethodException in dynamic Groovy and under @TypeChecked, or called another overload with null, and super.sp threw MissingPropertyException. Under @CompileStatic, super.sm() in a closure or lambda failed with IncompatibleClassChangeError for any static method of the superclass, hidden or not. All of them now reach the superclass's static member, as in javac. Private static methods of the superclass stay out of reach. The same change fixes super.first() in a closure or lambda of an ArrayList subclass under @CompileStatic, which failed with NoSuchMethodError, also when the subclass overrides first(): an extension method is a static method too, so it needs no super$ helper either.

class Base { static String sm() { 'base' } }
class Sub extends Base {
    static String sm() { 'sub' }
    String test() { super.sm() }  // threw MissingMethodException; now 'base'
}

How

The meta-class drops a method the class declares itself from the methods available to super calls, unless something takes its place: a package-private method of another run-time package (GROOVY-12570) or an extension method the class overrides (GROOVY-12522). Nothing took the place of a static method that hides one of the superclass. A super call now finds the hidden static method of the nearest superclass that has one; the super property index is built from the same methods, so the static property accessors resolve too. Under @CompileStatic, a static target needs no super$ helper in a closure: the call is an invokestatic, valid from any class.

Compatibility

COMPATIBILITY.md has the entry, "Groovy 7 — super reaches a static member the class hides (GROOVY-12519)". When a class declares a static method or property with the same signature as one of its superclass, super.sm() and super.sp within the class now call the superclass's member, in dynamic Groovy and under @TypeChecked, as javac and @CompileStatic do. They used to throw MissingMethodException or MissingPropertyException, or call another overload of the superclass with null. Under @CompileStatic, super.sm() in a closure or lambda for any static method of the superclass, and a call of an extension method through super there, no longer fails with IncompatibleClassChangeError or NoSuchMethodError.

Who is affected. Code that relied on the old failure or on the other overload being called. A private static method of the superclass stays out of reach. There are no API changes.

Tests

groovy.ThisAndSuperTest, in all three modes, including closures and lambdas, a static property read and written through super, a hidden method two levels up, a static method the class does not hide called from a closure and a lambda, the private case, and extension methods called through super from a closure and a lambda, also when the class overrides them. They fail without the change. On the tip, 14,482 tests in the groovy, bugs, gls, org.codehaus.groovy.classgen and groovy.transform.stc packages pass, including bugs.Groovy12570 and gls.innerClass.InnerClassTest, which cover the code master changed beside this. Before the latest merges of master, the transform, runtime, reflection, vmplugin, control and ast packages and the stub generator tests passed too. So did groovy-contracts, groovy-typecheckers, groovy-ginq, groovy-macro-library, groovy-json, groovy-xml and groovy-templates, every subproject compiled its main and test sources, and the Checkstyle and CodeNarc gates passed.

…the class hides

When a class declares a static method with the signature of a static
method of its superclass, the meta-class dropped the subclass method from
the methods available to super calls, as it does for any method declared
by the class itself, and nothing took its place: super.sm() threw
MissingMethodException, or picked another overload, and super.sp threw
MissingPropertyException for a static property. A super call now finds
the hidden static method of the nearest superclass that has one, as javac
does; the super property index is built from the same methods, so the
static property accessors resolve too. Private static methods of the
superclass stay out of reach.

Under static compilation, super.sm() in a closure or lambda went through a
super$ helper that called the static method with invokespecial
(IncompatibleClassChangeError). A static target needs no helper: the call
is an invokestatic, valid from any class.
… lambdas

The type checker no longer asks for a super$ helper for a static
target, and an extension method is a static method too. Statically
compiled, super.first() in a closure or super.last() in a lambda of an
ArrayList subclass called the extension method through a helper that
invoked ArrayList.first() with invokespecial, and failed with
NoSuchMethodError; 6.0.0 and master still do. The call is now a direct
static call.
@codecov-commenter

codecov-commenter commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.5899%. Comparing base (cb6cd05) to head (003a967).

Files with missing lines Patch % Lines
src/main/java/groovy/lang/MetaClassImpl.java 84.6154% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #3045        +/-   ##
==================================================
+ Coverage     74.5886%   74.5899%   +0.0013%     
  Complexity      45386      45386                
==================================================
  Files            1707       1707                
  Lines          153238     153250        +12     
  Branches        29461      29469         +8     
==================================================
+ Hits           114298     114309        +11     
- Misses          28424      28426         +2     
+ Partials        10516      10515         -1     
Files with missing lines Coverage Δ
...roovy/transform/stc/StaticTypeCheckingVisitor.java 88.0372% <100.0000%> (+0.0222%) ⬆️
src/main/java/groovy/lang/MetaClassImpl.java 80.0000% <84.6154%> (+0.0111%) ⬆️

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

@daniellansun daniellansun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for aligning dynamic super resolution and the SC closure path with javac for hidden static members.

Observations:

  1. Replacing a not-super-useful static declared on c with getHiddenStaticMethod in the MOP rewrite is the right place: it feeds both call sites and the super property index without a separate property path.

  2. Accessibility (public / protected / package-private same package, private out of reach) matches what we want for super static lookup. The private-static test is a useful guard.

  3. Short-circuiting checkSuperCallFromClosure for static targets avoids emitting a useless super$ helper and fixes the IncompatibleClassChangeError / extension-method NoSuchMethodError cases. Treating DGM as static here is consistent.

  4. The parameterized ThisAndSuperTest coverage (methods, properties, Mid→Base vs Low→Hider, closures/lambdas) makes the intended matrix easy to re-check.

Optional (non-blocking): a note in release notes that super.sm() / super.sp for a hidden static now succeed where they previously threw or picked another overload would help anyone who relied on the old failure. I have no blocking concerns on this tip.

@codeconsole

Copy link
Copy Markdown
Contributor Author

Added the note to COMPATIBILITY.md in 838b579, after merging master in. Thanks.

…-member

# Conflicts:
#	src/test/groovy/groovy/ThisAndSuperTest.groovy
The note is now in the pull request description. An entry carried on this branch conflicted with every later addition to the end of that file.

@daniellansun daniellansun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following up on tip 380d55696410. I re-checked the earlier COMMENT.

getHiddenStaticMethod in the MOP rewrite, the accessibility rules, short-circuiting checkSuperCallFromClosure for static targets, and the parameterized ThisAndSuperTest matrix still look right. CI is green on this tip.

One merge-time reminder only: the optional COMPATIBILITY.md note for the dynamic super.sm() / super.sp behaviour change is not on the current tip (left for the merge). Please restore a short “Who is affected” entry when landing, in the same style as GROOVY-12521, so the silent success path is documented for 6.0.x / 7.x readers.

Approving the code change.

…ethod the class does not hide

Under @CompileStatic this failed with IncompatibleClassChangeError before the
checkSuperCallFromClosure change, hidden method or not.
In the shape of the GROOVY-12521 entry, with a "Who is affected" paragraph,
and including the @CompileStatic closure and lambda case for a static method
the class does not hide.
@codeconsole

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review. The GROOVY-12519 entry is back in COMPATIBILITY.md in 003a967, after merging master in (984527e) so it sits on the current end of the file. It follows the GROOVY-12521 layout, with a "Who is affected" paragraph. While writing it I found that the @CompileStatic closure and lambda fix covers any static method of the superclass called through super, not only a hidden one: super.sm() from a closure failed with IncompatibleClassChangeError even when the class doesn't declare sm(). The entry says so, and f9c39c9 adds testSuperDotStaticMethodInClosure for it, which fails under @CompileStatic without the change. I checked the "another overload with null" wording against the code without the fix: super.sm() there called Base.sm(String) with null.

@daniellansun daniellansun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Scott. I re-reviewed tip 003a967bcc78703ee3ee32464f8c36ab23ec9319 against my earlier approval on 380d55696410.

The production change is unchanged: getHiddenStaticMethod still feeds both super.sm() and super.sp, accessibility is the same (a private static method of the superclass stays out of reach), and checkSuperCallFromClosure still returns early for a static target so SC does not emit a super$ helper.

Thank you for restoring the COMPATIBILITY.md entry, and for testSuperDotStaticMethodInClosure. I agree the @CompileStatic closure and lambda path applies to any static method of the superclass called through super, not only a hidden one, and the new test plus the "Who is affected" wording make that clear. The earlier reminder is settled.

CI is green on this tip. Looks good to me.

…-member

Conflicts:
- MetaClassImpl: master added superMethodOfAnotherRuntimePackage (GROOVY-12570)
  and getHiddenExtensionMethod (GROOVY-12522) where this branch added
  getHiddenStaticMethod. The first two take only instance methods, the last
  only static ones, so a method that is not fit for super usage now tries all
  three in turn, and all three helpers are kept.
- ThisAndSuperTest: both sides added tests at the same place; both kept.
- COMPATIBILITY.md: both sides appended entries; master's come first, then
  the GROOVY-12519 entry.
…en the class overrides it

The GROOVY-12522 test left @CompileStatic out, which failed with
NoSuchMethodError there. With no super$ helper for a static target, the
closure calls the extension method directly.
@codeconsole

Copy link
Copy Markdown
Contributor Author

Merged master in (9f46536). MetaClassImpl conflicted with GROOVY-12570 and GROOVY-12522, which added superMethodOfAnotherRuntimePackage and getHiddenExtensionMethod in the same place as getHiddenStaticMethod. Theirs only return an instance method and this one only a static method, so a method that isn't fit for super now tries all three in turn. ThisAndSuperTest and COMPATIBILITY.md only conflicted because both sides added to the same place, and both are kept. One interaction: the new GROOVY-12522 closure test left @CompileStatic out, where super.first() from a closure of a class that overrides first() failed with NoSuchMethodError. With no super$ helper for a static target it now works, so ea730c7 adds that mode to the test.

@testlens-app

This comment has been minimized.

@daniellansun daniellansun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Scott — I re-checked the published tip ea730c795eac. It does include the merge you named: 9f465365af is the parent, against master ca71425976, and ea730c795e then adds @CompileStatic to the GROOVY-12522 super.first() closure test.

The unique change is still correct. getHiddenStaticMethod still feeds both super.sm() and super.sp, a private static method of the superclass stays out of reach, and checkSuperCallFromClosure still returns early for a static target so SC does not emit a super$ helper. The MetaClassImpl resolution against GROOVY-12570 and GROOVY-12522 looks right: superMethodOfAnotherRuntimePackage and getHiddenExtensionMethod take only instance methods, getHiddenStaticMethod takes only static methods, and a method that is not fit for super now tries all three in turn. I also agree that super.first() from a @CompileStatic closure of a class that overrides first() should be in ThisAndSuperTest; with no super$ helper for a static target, the closure can call the extension method directly.

GitHub still reports a conflict because this tip's merge is against ca71425976, not current master. The only conflict with e3b8697e97 is COMPATIBILITY.md: both sides appended a Groovy 7 section at the same place (this PR's GROOVY-12519 entry, and master's GROOVY-12562 entry from 097708c30c). MetaClassImpl and ThisAndSuperTest do not conflict. Please merge current master and keep both entries, with the 12562 section first and then 12519, as you did on the previous compatibility-file conflict.

CI on this tip is red on the same four trait/lambda tests that were red on master after #3244. Those are fixed on current master in f1cf705346 and e3b8697e97. I am not adding another approval on a conflicting, red tip; the existing approval of the 12519 change still stands once the conflict is resolved and CI is green.

One compatibility note, not a request to change the entry: it is already written as a Groovy 7 behaviour change, which is right. In dynamic Groovy and under @TypeChecked, super.sm() / super.sp for a hidden static member now succeed, or bind differently, where they previously threw or called another overload with null. I would not cherry-pick this as a unit to GROOVY_6_0_X unless that new success path is accepted for 6.0.x as well. The @CompileStatic closure and lambda fix is a separate bug fix (it used to fail with IncompatibleClassChangeError or NoSuchMethodError).

@daniellansun
daniellansun merged commit 4b33d54 into apache:master Nov 22, 2026
3 of 25 checks passed
@daniellansun

Copy link
Copy Markdown
Contributor

Merged. Thanks!

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.

3 participants