fix: handle null argument in GORM domain class constructor (Groovy 4 regression)#15482
Closed
davydotcom wants to merge 1 commit into7.0.xfrom
Closed
fix: handle null argument in GORM domain class constructor (Groovy 4 regression)#15482davydotcom wants to merge 1 commit into7.0.xfrom
davydotcom wants to merge 1 commit into7.0.xfrom
Conversation
…regression) In Groovy 3, calling new DomainClass(null) was resolved by the runtime to the implicit map-based constructor and treated equivalently to new DomainClass(). Groovy 4 changed how constructor resolution works at runtime and no longer matches a null argument to the implicit map constructor, resulting in: GroovyRuntimeException: Could not find matching constructor for: DomainClass(null) This commit injects an explicit Map constructor into GORM entity classes via GormEntityTransformation. The constructor handles null gracefully by skipping property assignment, making it behave identically to the no-arg constructor. A corresponding no-arg constructor is also ensured since adding any explicit constructor prevents Groovy from auto-generating the default one. Co-Authored-By: Oz <oz-agent@warp.dev>
Contributor
|
Closing this, i think teh core issue was the rest transforms weren't included in your project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Calling
new DomainClass(null)on a GORM domain class throws:This is a regression from Grails 6 / Groovy 3, where
new DomainClass(null)was treated equivalently tonew DomainClass().Root Cause
In Groovy 3, the runtime resolved
new SomeClass(null)by matching it to the implicit map-based constructor that Groovy provides for POGOs. Whennullwas passed, the runtime simply created the object via the no-arg constructor without setting any properties.Groovy 4 changed how constructor resolution works at runtime. The implicit map constructor is no longer matched when
nullis passed as the argument, causing theGroovyRuntimeException.This is a common pattern in Grails applications — for example, when a variable that may be
nullis passed to a domain constructor:Fix
The
GormEntityTransformation(the@EntityAST transform) now injects an explicitMapconstructor into every GORM entity class. The constructor:Mapparameter, allowingnullto match at runtimenull, sets properties viaInvokerHelper.setProperties(this, args)— the same mechanism Groovy uses internally for map constructorsnull, does nothing (equivalent to the no-arg constructor)The constructor is injected early in the transformation (before trait composition), so trait
\$init\$methods are properly wired into it by the Groovy trait composer.Tests
Added
NullConstructorArgSpecingrails-data-hibernate5/corewith three tests:All 598 existing hibernate5 core tests continue to pass with 0 failures.
Co-Authored-By: Oz oz-agent@warp.dev