Skip to content

GROOVY-12257: Restore ObjectUtil as a binary-compatibility facade for… - #2788

Merged
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy12257
Aug 15, 2026
Merged

GROOVY-12257: Restore ObjectUtil as a binary-compatibility facade for…#2788
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy12257

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

… Groovy 4 compiled @immutable classes

The @immutable transform in Groovy 4.0.5 through 4.0.x (GROOVY-10747) emitted references to org.apache.groovy.runtime.ObjectUtil.cloneObject into generated constructors and getters for defensive copies. The class was removed along with the $getLookup machinery it relied on (GROOVY-10931), so such pre-compiled classes fail on Groovy 5+ with NoClassDefFoundError at first instantiation — only when a clone path actually executes, which for collection properties depends on the runtime value being Cloneable, making the failure intermittent.

Restore the class as a deprecated facade with the original semantics minus the lookup dependency: null passes through, non-Cloneables throw CloneNotSupportedException, arrays clone via the unchanged ArrayUtil fast paths, and other Cloneables clone through their public clone() via the MOP (guarded by the same getMethod check as the original, so a non-public clone() still surfaces NoSuchMethodException). Nothing compiled by Groovy 5+ references the class; current transforms emit indy or InvokerHelper clone calls instead.

Verified against real Groovy 4.0.33 bytecode: the reproducer's List property shape and the unconditional array/getter shape both fail with NoClassDefFoundError before this change and pass with it, preserving defensive-copy semantics.

@codecov-commenter

codecov-commenter commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.1276%. Comparing base (142130d) to head (10b3130).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...ain/java/org/apache/groovy/runtime/ObjectUtil.java 92.0000% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2788        +/-   ##
==================================================
+ Coverage     70.1064%   70.1276%   +0.0212%     
- Complexity      35774      35799        +25     
==================================================
  Files            1561       1562         +1     
  Lines          132373     132400        +27     
  Branches        24332      24345        +13     
==================================================
+ Hits            92802      92849        +47     
+ Misses          31170      31156        -14     
+ Partials         8401       8395         -6     
Files with missing lines Coverage Δ
...ain/java/org/apache/groovy/runtime/ObjectUtil.java 92.0000% <92.0000%> (ø)

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

This comment has been minimized.

… Groovy 4 compiled @immutable classes

The @immutable transform in Groovy 4.0.5 through 4.0.x (GROOVY-10747)
emitted references to org.apache.groovy.runtime.ObjectUtil.cloneObject
into generated constructors and getters for defensive copies. The class
was removed along with the $getLookup machinery it relied on
(GROOVY-10931), so such pre-compiled classes fail on Groovy 5+ with
NoClassDefFoundError at first instantiation — only when a clone path
actually executes, which for collection properties depends on the
runtime value being Cloneable, making the failure intermittent.

Restore the class as a deprecated facade with the original semantics
minus the lookup dependency: null passes through, non-Cloneables throw
CloneNotSupportedException, arrays clone via the unchanged ArrayUtil
fast paths, and other Cloneables clone through their public clone()
via the MOP (guarded by the same getMethod check as the original, so a
non-public clone() still surfaces NoSuchMethodException). Nothing
compiled by Groovy 5+ references the class; current transforms emit
indy or InvokerHelper clone calls instead.

Verified against real Groovy 4.0.33 bytecode: the reproducer's List
property shape and the unconditional array/getter shape both fail with
NoClassDefFoundError before this change and pass with it, preserving
defensive-copy semantics.
@paulk-asert
paulk-asert merged commit 31803c5 into apache:master Aug 15, 2026
29 checks passed
@paulk-asert
paulk-asert deleted the groovy12257 branch August 15, 2026 20:38
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