Skip to content

GROOVY-12146: order reflection calls to ensure Annotation members are ordered#2690

Open
jdaugherty wants to merge 1 commit into
apache:GROOVY_5_0_Xfrom
jdaugherty:GROOVY_5_0_X
Open

GROOVY-12146: order reflection calls to ensure Annotation members are ordered#2690
jdaugherty wants to merge 1 commit into
apache:GROOVY_5_0_Xfrom
jdaugherty:GROOVY_5_0_X

Conversation

@jdaugherty

Copy link
Copy Markdown
Contributor

Code changes:

  • Added ReflectionUtils#getDeclaredMethodsSorted(Class), #getDeclaredFieldsSorted(Class), and #getDeclaredConstructorsSorted(Class): deterministic-order variants of the JDK reflection calls (methods sorted by name then signature, fields by name, constructors by signature), with javadoc documenting the nondeterminism and why callers whose output feeds bytecode generation must use them.
  • Java8#configureClassNode now uses the sorted variants for methods, fields, and constructors, so member order in reflection-backed ClassNodes — and everything derived from it — is deterministic.
  • Refactored the GROOVY-12146 fix in Java8#configureAnnotation to reuse getDeclaredMethodsSorted instead of its inline sort, centralizing the sorting so future callers don't repeat it ad hoc.

Sorting is behavior-neutral: member order carries no semantic meaning in these paths; it only affects the byte layout of emitted class files.

@jdaugherty

Copy link
Copy Markdown
Contributor Author

@paulk-asert I found more issues after verifying the restage. MOP bridge methods & Woven trait methods. I used a similar fix and extracted the logic to a shared location.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.2476%. Comparing base (ff64047) to head (c211095).

Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                   @@
##             GROOVY_5_0_X      #2690        +/-   ##
======================================================
- Coverage         67.2505%   67.2476%   -0.0029%     
- Complexity          29569      29570         +1     
======================================================
  Files                1382       1382                
  Lines              116991     116999         +8     
  Branches            20551      20551                
======================================================
+ Hits                78677      78679         +2     
- Misses              31787      31791         +4     
- Partials             6527       6529         +2     
Files with missing lines Coverage Δ
...rg/codehaus/groovy/reflection/ReflectionUtils.java 46.4646% <100.0000%> (+5.3535%) ⬆️
...in/java/org/codehaus/groovy/vmplugin/v8/Java8.java 78.4483% <100.0000%> (-0.0618%) ⬇️

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

@jdaugherty jdaugherty marked this pull request as ready for review July 12, 2026 02:56
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