Repository navigation
Conversation
Groovy 5 changed runtime method selection for classes implementing Map: for a String key, DefaultGroovyMethods.getAt(Object, String) and putAt(Object, String, Object) now win over the Map overloads, so subscript and property access resolved to a JavaBean property instead of a map entry. Entries named after an accessor became unreachable — params['request'] returned the HttpServletRequest and params['identifier'] = value threw ReadOnlyPropertyException. AbstractTypeConvertingMap now declares getAt(String)/putAt(String, Object) and map-first getProperty/setProperty, restoring the Grails 7 rule for GrailsParameterMap and GroovyPageAttributes. metaClass stays exempt from property access so Groovy's own machinery keeps working. GrailsParameterMap.getIdentifier() prefers a parameter literally named identifier, falling back to the id parameter as before. Also adds the JUnit 5 engine to grails-taglib, whose only JUnit 5 test was never being discovered. Fixes #16280
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16281 +/- ##
==================================================
+ Coverage 54.7149% 54.7184% +0.0035%
- Complexity 20421 20436 +15
==================================================
Files 2101 2101
Lines 100978 100988 +10
Branches 17907 17907
==================================================
+ Hits 55250 55259 +9
- Misses 37860 37863 +3
+ Partials 7868 7866 -2
🚀 New features to boost your workflow:
|
| * | ||
| * @return the {@code identifier} parameter when one is present, otherwise the {@code id} parameter | ||
| */ | ||
| public Object getIdentifier() { |
There was a problem hiding this comment.
This is what triggered the error I discovered, that a test would not allow me to do:
params.identifier = "123"
|
The error occurs because |
matrei
left a comment
There was a problem hiding this comment.
AI review:
Review Findings
[P1] Preserve id precedence in getIdentifier()
File: grails-web-common/src/main/groovy/grails/web/servlet/mvc/GrailsParameterMap.java:248-253
This changes the existing getIdentifier() contract from always returning the id parameter to returning the identifier parameter whenever that key exists.
Controller.initializeCommandObject() calls params.getIdentifier() at grails-controllers/src/main/groovy/grails/artefact/Controller.groovy:377 when resolving a domain command object without a prefixed identifier. Consequently, a request such as:
?id=1&identifier=2
previously loaded entity 1, but now attempts to load entity 2. A normal form field named identifier can therefore cause a controller to load or update the wrong domain object.
The map-access fix already makes params.identifier available as a map entry, so changing the explicit getIdentifier() behavior is unnecessary and conflicts with issue #16280's expected behavior that this method continues returning the id entry.
Please restore the original implementation:
public Object getIdentifier() {
return get(GormProperties.IDENTITY);
}Please also add a controller-level regression test covering a request containing both id and identifier parameters.
Verification
The following focused checks passed:
:grails-web-common:test --tests 'grails.web.servlet.mvc.GrailsParameterMapTests':grails-core:test --tests 'org.grails.util.TypeConvertingMapTests':grails-taglib:test --tests 'org.grails.taglib.GroovyPageAttributesTests':grails-test-suite-web:test --tests 'org.grails.web.commandobjects.CommandObjectInstantiationSpec':grails-web-common:validateDependencyVersions:grails-taglib:validateDependencyVersions:grails-core:validateDependencyVersions
No additional actionable findings were identified.
Review feedback on #16281: Controller.initializeCommandObject() passes params.getIdentifier() to Type.get() when resolving a domain command object, so letting a submitted field named "identifier" take precedence meant a request with ?id=1&identifier=2 loaded entity 2. Restore the original contract — getIdentifier() reads the id parameter only. The map-access fix already makes a parameter named "identifier" reachable as params['identifier'] and params.identifier, which is what #16280 asked for; the accessor does not need to change. Adds a controller-level regression test covering a request carrying both id and identifier, verified to fail without this commit.
|
Thanks @matrei — confirmed and fixed in 0093ab2. I verified the failure path before acting on it:
The map-access fix is untouched and still delivers what #16280 asked for — Added the regression test you asked for: Docs updated to match: Re-verified locally: |
matrei
left a comment
There was a problem hiding this comment.
AI review, round 2:
Review Findings
[P1] Preserve map-entry property access for statically compiled Groovy
Files:
grails-core/src/main/groovy/grails/util/AbstractTypeConvertingMap.java:395-400grails-core/src/main/groovy/grails/util/AbstractTypeConvertingMap.java:411-417
The new getProperty() and setProperty() overrides only affect dynamic Groovy property dispatch. @CompileStatic resolves properties against the declared Java type at compile time and bypasses these methods.
With Groovy 5, a probe against the compiled PR classes shows:
// dynamic Groovy
map.identifier // map entry
// @CompileStatic Groovy
map.identifier // getIdentifier()
map.identifier = ... // compilation error:
// Cannot set read-only property: identifierThis affects params, whose public getParams() API returns GrailsParameterMap at grails-web-common/src/main/groovy/grails/web/api/WebAttributes.groovy:124-132. In statically compiled controllers or other consumers:
params.identifiercan still resolve togetIdentifier()rather than theidentifiermap entry.params.requestcan still resolve togetRequest()rather than therequestmap entry.params.identifier = valuecan still fail compilation.
The upgrade documentation unconditionally says that params['name'], params.name, attrs['name'], and attrs.name always address map entries at grails-doc/src/en/guide/upgrading/upgrading80x.adoc:1497-1499, which is not true for statically compiled code.
Please either make the implementation cover the supported static-compilation paths or document and test this limitation. The affected tests currently exercise only dynamically compiled Groovy.
Resolved Prior Finding
The earlier getIdentifier() precedence issue is fixed. GrailsParameterMap.getIdentifier() again reads only the id parameter at grails-web-common/src/main/groovy/grails/web/servlet/mvc/GrailsParameterMap.java:248-250, and the controller-level regression test covers requests containing both id and identifier at grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectInstantiationSpec.groovy:130-156.
Verification
The focused tests and compilation checks passed:
:grails-core:test --tests 'org.grails.util.TypeConvertingMapTests':grails-web-common:test --tests 'grails.web.servlet.mvc.GrailsParameterMapTests':grails-taglib:test --tests 'org.grails.taglib.GroovyPageAttributesTests':grails-test-suite-web:test --tests 'org.grails.web.commandobjects.CommandObjectInstantiationSpec':grails-core:compileGroovy :grails-web-common:compileGroovy :grails-controllers:compileGroovygit diff --check
Review feedback on #16281: the getProperty/setProperty overrides only affect dynamic Groovy dispatch. Under @CompileStatic the compiler binds property syntax to the declared accessor, so params.identifier calls getIdentifier() and params.request calls getRequest() rather than reading the map entry, and assigning to them does not compile. Verified against the compiled classes: params['identifier'] = v ok, writes the map entry params['identifier'] ok, reads the map entry params['request'] ok, reads the map entry params['request'] = v compile error, String vs HttpServletRequest params.identifier = v compile error, read-only property params.identifier getIdentifier() params.request getRequest() The upgrade note no longer claims the rule holds unconditionally, and carries a NOTE covering the two colliding names with the portable workaround (subscript to read, put() to write). The controllers guide carries the same qualification. Adds a @CompileStatic test pinning the statically compiled behaviour, which previously was only exercised dynamically.
|
Thanks @matrei — documented and tested in c9e3c0f. I probed the compiled classes rather than taking the description as given, and the picture is slightly sharper than the finding states. Under
So the subscript read is fine statically for both names — it is the subscript write for I went with documenting rather than chasing the implementation. Covering static compilation would mean removing Changes:
Re-verified: |
jdaugherty
left a comment
There was a problem hiding this comment.
Reviewed against c9e3c0f. I reproduced the dispatch change independently — a minimal replica of AbstractTypeConvertingMap run under Groovy 4.0.33 and 5.1.0 — and re-checked every conclusion against the real classes, including one mutation of getIdentifier() to test what the new specs actually pin.
The approach is right, and c9e3c0f already covers the params half of the static-compilation caveat I was going to raise, with a test that passes. Nice. What is left:
1. attrs / GroovyPageAttributes is the half that is still uncovered, and it is the worse one. The new NOTE in §28.3 and testStaticCompilationBindsPropertySyntaxToTheAccessor both scope themselves to params. On params the statically compiled write at least fails loudly at compile time. On attrs it does not: gspTagSyntaxCall has a real setter, so attrs.gspTagSyntaxCall = false under @CompileStatic compiles fine and silently writes the field while leaving the map untouched — the exact failure mode the PR description cites as motivation.
2. Dotted and subscript assignment to a name backed by a real setter no longer invokes that setter, in dynamically compiled code too. This is independent of static compilation and is not mentioned anywhere. On Groovy 4 both attrs.gspTagSyntaxCall = false and attrs['gspTagSyntaxCall'] = false called setGspTagSyntaxCall; here both write a map entry and leave the flag at its default. I checked the framework and it only ever uses the two-arg constructor and the explicit setter/getter, so nothing in grails-core regresses — the exposure is third-party taglib and plugin code. Worth a line in §28.3 and a test either way.
3. The description is out of date. It still says getIdentifier() "now prefers a parameter literally named identifier and otherwise falls back to the conventional id parameter", but after 0093ab2 the method is return get(GormProperties.IDENTITY) — the diff there is Javadoc only. Worth fixing since the description is what reviewers read first.
Confirmed correct, so it does not need re-litigating:
- The dynamic read path matches Grails 7 on every case I probed, and the
metaClassnote is accurate — ametaClassparameter really did shadow it on Groovy 4, andparams['metaClass']still reads the entry. map.class,map.emptyandmap.sizeare unchanged from Grails 7. Groovy was already map-first for dotted reads on aMap-implementingGroovyObject, soattrs.class == 'container'documents existing behavior rather than something new here.- The
junit-jupiter-engineaddition is a real catch, not incidental. Reverting only that line makes:grails-taglib:testreport BUILD SUCCESSFUL while discovering zero tests. The six other modules that declare the API without the engine all receive it transitively, sograils-taglibwas the only silently-empty one. - Tests pass as claimed:
TypeConvertingMapTests16,GrailsParameterMapTests36,GroovyPageAttributesTests7,CommandObjectInstantiationSpec15, plus full:grails-core:testand:grails-web-common:test.codeStyleclean on all three modules. The existing multi-key subscripttheMap['name','dob']still resolves through DGM despite the newgetAt(String). - No conflicting
getProperty/getAtoverrides anywhere in the hierarchy, and no framework code reaches the colliding names via property access.
One out-of-scope note: the same Groovy 5 shape exists in other Map implementations exposing no-arg getters — LazyMetaPropertyMap (implements Map, public Object getInstance()), DirtyCheckingMap, JSONObject. Not asking for it here; may be worth a follow-up issue.
| * @since 8.0.0 | ||
| */ | ||
| @Override | ||
| public void setProperty(String name, Object value) { |
There was a problem hiding this comment.
setProperty routes every non-metaClass name to put, which also changes assignment for names backed by a real settable bean property — not only the read-only getters this PR is about. That is a dynamic-path change, independent of the static-compilation caveat documented in c9e3c0f.
The only such property in this hierarchy is GroovyPageAttributes.gspTagSyntaxCall. Verified with a replica carrying a settable flag property:
Groovy 4.0.33 (no override)
dynamic m.flag = false -> field=false, mapEntry=null # setter invoked
dynamic m['flag'] = false -> field=false, mapEntry=null # setter invoked
Groovy 5.1.0 (this PR)
dynamic m.flag = false -> field=true, mapEntry=false # setter skipped
dynamic m['flag'] = false -> field=true, mapEntry=false # setter skipped
So on Grails 7 both forms called setGspTagSyntaxCall; here both write a map entry and leave the flag at its default. Reads were already map-first on Groovy 4, so this is specifically a write-side change and it is not in §28.3.
I checked how the framework sets the flag: only the two-arg constructor (new GroovyPageAttributes(attrs, false) in TagOutput) and the explicit setGspTagSyntaxCall/isGspTagSyntaxCall methods. So nothing inside grails-core regresses. The exposure is third-party taglib or plugin code using the property form — it would silently stop suppressing auto-printing, and the stray gspTagSyntaxCall entry then travels with the attribute map into whatever renders remaining attributes.
Either exempting names that have a real setter, or documenting this in §28.3 and pinning it with a test, would close it. A test that passes today and captures the difference is suggested on GroovyPageAttributesTests.
Minor, same method: the metaClass branch could be return getMetaClass(); / setMetaClass(...) instead of round-tripping through super.getProperty(name), which re-enters the metaclass to resolve a property this class now intercepts. Cheaper per read and avoids the self-referential path.
| * @since 8.0.0 | ||
| */ | ||
| @Override | ||
| public Object getProperty(String name) { |
There was a problem hiding this comment.
c9e3c0f documents the static-compilation caveat well for params, and I verified testStaticCompilationBindsPropertySyntaxToTheAccessor passes. Two notes on scope, since this override is the shared base for both maps:
attrs is not covered, and it fails more quietly than params. Both the new NOTE and the new test scope themselves to params. GroovyPageAttributesTests has no @CompileStatic coverage at all. The difference matters: on params, statically compiled assignment to a colliding name fails at compile time, which is loud. On attrs, gspTagSyntaxCall has a real setter, so it compiles and silently does the wrong thing. Verified against the real class on Groovy 5.1.0:
dynamic attrs.gspTagSyntaxCall = false -> mapEntry=false, field=true # as intended
@CompileStatic attrs.gspTagSyntaxCall = false -> mapEntry=null, field=false # setter invoked, map untouched
dynamic attrs.gspTagSyntaxCall (read) -> the map entry
@CompileStatic attrs.gspTagSyntaxCall (read) -> the boolean field
The subscript form is correct in both modes, as with params.
Worth stating the underlying rule once, rather than per name. The reason the caveat exists is structural: getProperty/setProperty are runtime hooks, so the static compiler binds to the declared accessor and never reaches them, while getAt(String)/putAt(String, Object) are declared methods it resolves directly. That is why subscript is the portable form for any colliding name on either map — including ones a subclass adds later. A sentence to that effect in the Javadoc here would keep the guidance from having to be re-derived for each new accessor.
For reference, measured on Groovy 4.0.33 vs 5.1.0 with the real classes — the Groovy 4 static and dynamic columns were identical, so the divergent rows are Grails 7 → 8 changes rather than pre-existing quirks:
| expression | Grails 7 (Groovy 4) | this PR, dynamic | this PR, @CompileStatic |
|---|---|---|---|
params.identifier read |
map entry | map entry | getIdentifier() → the id param |
params.request read |
map entry | map entry | the HttpServletRequest |
params.identifier = 'x' |
map put | map put | compile error |
params['identifier'] read/write |
map | map | map |
attrs.gspTagSyntaxCall read |
map entry | map entry | the boolean field |
attrs.gspTagSyntaxCall = false |
setter invoked | map put | setter invoked, map untouched |
|
|
||
| assertFalse attrs.isGspTagSyntaxCall() | ||
| assertEquals 'value', attrs['gspTagSyntaxCall'] | ||
| } |
There was a problem hiding this comment.
This covers the read side and the explicit setGspTagSyntaxCall(false) method form, but never attrs.gspTagSyntaxCall = false — the property-assignment form, which is what the new setProperty override changes. Since this is the only settable bean property in the hierarchy, it is the case worth pinning.
Two tests, both of which I ran against c9e3c0f. The first passes and captures the dynamic write-side change from Grails 7:
// https://github.com/apache/grails-core/issues/16280
@Test
void testPropertyAssignmentDoesNotInvokeTheSetter() {
def attrs = toGroovyPageAttributes([:])
attrs.gspTagSyntaxCall = false
assertEquals false, attrs['gspTagSyntaxCall']
assertTrue attrs.isGspTagSyntaxCall()
}On Groovy 4 that same line invoked setGspTagSyntaxCall(false) and stored nothing in the map, so this is the assertion that documents the difference.
The second fails today, and is the attrs counterpart of testStaticCompilationBindsPropertySyntaxToTheAccessor:
// https://github.com/apache/grails-core/issues/16280
@Test
void testStaticallyCompiledAttributeAccessAddressesTheMap() {
def attrs = toGroovyPageAttributes([:])
StaticallyCompiledAccess.write(attrs)
assertEquals false, attrs['gspTagSyntaxCall']
assertTrue attrs.isGspTagSyntaxCall()
}
@CompileStatic
static class StaticallyCompiledAccess {
static void write(GroovyPageAttributes attrs) {
attrs.gspTagSyntaxCall = false
}
}Both need import groovy.transform.CompileStatic. The second fails with expected: <false> but was: <null> — the map entry was never written and the field was.
If the attrs static behavior is accepted as a documented limitation like params, then inverting that second assertion (asserting the field was written and the map was not) is the right form — it still locks the behavior down and makes it discoverable instead of silent. Either way I'd not leave it untested, since this is the one case with no compile error to warn the caller.
| } | ||
| ---- | ||
|
|
||
| Every other parameter name is unaffected, and the subscript form behaves the same under both compilation modes. |
There was a problem hiding this comment.
This NOTE is a good addition and matches what I measured. Two gaps:
It only addresses params. attrs (GroovyPageAttributes) has the same static-compilation behavior, and there it is quieter, because gspTagSyntaxCall has a real setter — attrs.gspTagSyntaxCall = false under @CompileStatic compiles and silently writes the field. Since the section header covers both params and attrs, a reader will reasonably assume the NOTE does too. Suggest either naming attrs here or generalising: subscript is the portable form for any accessor-colliding name on either map.
"Every other parameter name is unaffected" is true only for reads. Assignment to a name backed by a real setter also changed, in dynamically compiled code: on Grails 7 attrs.gspTagSyntaxCall = false and attrs['gspTagSyntaxCall'] = false both invoked setGspTagSyntaxCall, and both now write a map entry instead. That is a second difference from Grails 7 alongside the metaClass read, and it is currently undocumented.
| Every other parameter name is unaffected, and the subscript form behaves the same under both compilation modes. | ||
| ==== | ||
|
|
||
| One behavior differs from Grails 7: `params.metaClass` always returns the Groovy `MetaClass`. |
There was a problem hiding this comment.
Worth extending this paragraph to the write side, which the metaClass guard makes asymmetric. Verified on Groovy 5.1.0:
params['metaClass'] = 'mc' // stores a map entry
params.metaClass = 'mc' // GroovyCastException: Cannot cast object 'mc' ... to class 'groovy.lang.MetaClass'As written the paragraph only tells readers about reading params['metaClass'], so the exception on the dotted form is a surprise. One sentence covers it.
|
|
||
| then: 'the command object is resolved from id, not from the identifier field' | ||
| response.status == HttpServletResponse.SC_OK | ||
| model.commandObject.id == target.id |
There was a problem hiding this comment.
These two conditions are not actually sensitive to getIdentifier(), so the integration half of this test does not exercise the mechanism its name describes.
I verified by mutation — changing GrailsParameterMap.getIdentifier() to return get("identifier") and re-running. model.commandObject.id == target.id and model.commandObject.name == 'Target' both still passed; the only condition that failed was the direct params.getIdentifier() == target.id further down.
The reason is that Controller.initializeCommandObject reads commandObjectBindingSource.getIdentifierValue() first and only falls back to params.getIdentifier() when that returns null. DefaultDataBindingSourceCreator builds that source as new SimpleMapDataBindingSource(grailsWebRequest.getParams()), whose getIdentifierValue() returns map['id'] — already target.id here — so the fallback never runs.
So the coverage comes entirely from the direct assertion, which duplicates GrailsParameterMapTests.testGetIdentifierAlwaysReadsTheIdParameter. To pin the mechanism at this level, drive the fallback — e.g. a binding source with no id key, so getIdentifierValue() returns null and getIdentifier() is actually consulted. Otherwise the spec is fine but the "does not divert domain command object resolution" claim rests on the unit test rather than on this one.
| testImplementation 'org.junit.jupiter:junit-jupiter-api' | ||
| testImplementation 'org.slf4j:slf4j-nop' // Get rid of warning about missing slf4j implementation during compilation and tests | ||
| testImplementation 'org.spockframework:spock-core' | ||
| testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' // Required to discover the JUnit 5 tests in this module |
There was a problem hiding this comment.
Confirmed this is a real gap and not a no-op: reverting only this line makes :grails-taglib:test report BUILD SUCCESSFUL while discovering zero tests, so GroovyPageAttributesTests had never executed.
Worth considering whether it belongs in gradle/test-config.gradle instead. That convention already adds testRuntimeOnly 'org.junit.platform:junit-platform-launcher' and calls useJUnitPlatform(), but never adds the Jupiter engine — which is why the failure mode existed at all. Every other module with JUnit 5 tests gets the engine only transitively, through runtimeOnly 'org.junit.jupiter:junit-jupiter-engine' in grails-testing-support-core; I checked the six modules that declare junit-jupiter-api without an explicit engine and they all resolve it that way today. If that transitive edge is ever narrowed, the same silent-skip returns elsewhere with a green build.
Fine to keep the module-local fix and do the convention change separately, but it would be the fix for the class of problem rather than this instance.
|
|
||
| assertEquals 'mc', theMap['metaClass'] | ||
| assertNotNull theMap.metaClass | ||
| assertNotEquals 'mc', theMap.metaClass |
There was a problem hiding this comment.
Nit: this does catch the metaClass guard being removed — the property would then return the string 'mc' — but only because of the specific value stored above. With any other value it would be vacuous, since a String is never equal to a MetaClass.
The grails-core twin states the intent directly:
assert map.metaClass instanceof MetaClassWorth matching here for consistency.
Review feedback on #16281, all three points verified locally first. The attrs half of the static-compilation caveat was uncovered, and it is the quieter one: gspTagSyntaxCall has a real setter, so under @CompileStatic "attrs.gspTagSyntaxCall = false" compiles and silently drives the flag while leaving the map untouched, where the equivalent on params fails at compile time. Assignment to a setter-backed name also changed in dynamically compiled code, which was undocumented. Probing a replica with and without this PR's fix on Groovy 4.0.30 and 5.0.6 shows the change comes from the fix, not from Groovy 5: without it both the dotted and subscript forms called setGspTagSyntaxCall on either Groovy version; with it both write a map entry. Nothing in the framework depends on the old routing. The controller-level regression test did not exercise the mechanism its name described. Controller.initializeCommandObject reads commandObjectBindingSource.getIdentifierValue() first, and SimpleMapDataBindingSource returns map['id'], so submitting an id meant the params.getIdentifier() fallback never ran. Rewritten to submit only an identifier parameter, which drives the fallback; mutation-checked to fail on the command object resolution rather than on a duplicated assertion. Also documents that assigning params.metaClass throws rather than storing an entry, and pins that with a test. No production code changes.
|
Thanks @jdaugherty — this was a genuinely useful review. All three points addressed in 1d0096c, and I verified each independently first. No production code changed. 1. So the setter-backed write change is caused by this PR, not by Groovy 5 — it is a second Grails 7 delta alongside the For the static case I took the "document and test the actual behavior" option you suggested: 2. You are right that my controller test did not exercise the mechanism, and my earlier claim that it did was wrong. Rewritten to submit only an — the resolution itself. A second test keeps the Worth noting this also means the originally-cited 3. Description updated. It now states that Docs: the §28.3 NOTE now covers both maps and names the silent Nit: taken, now Follow-ups filed rather than widened into this PR:
Re-verified: |
🚨 TestLens detected 2 failed tests 🚨Here is what you can do:
Test SummaryCI / Functional Tests (Java 21, indy=false, shard 1) > :grails-test-examples-gsp-sitemesh3:integrationTest
CI / Functional Tests (Java 25, indy=false, shard 1) > :grails-test-examples-gsp-sitemesh3:integrationTest
🏷️ Commit: 1d0096c Test FailuresEndToEndSpec > async multiple levels of layouts (:grails-test-examples-gsp-sitemesh3:integrationTest in CI / Functional Tests (Java 21, indy=false, shard 1))
EndToEndSpec > async multiple levels of layouts (:grails-test-examples-gsp-sitemesh3:integrationTest in CI / Functional Tests (Java 25, indy=false, shard 1))
Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
|
I know the AI suggested documenting our way out of this, but I think we need to actually fix / restore this behavior. |
|
@jdaugherty Please have a go at it, as it has passed a point where I'm not confident that I have the solution. |
|
Closing in favour of #16293, which takes the approach you asked for, @jdaugherty. Two things came out of taking another run at it. The root cause is not what this PR's description claims. I attributed it to
So the trigger is just: a public JavaBean accessor on a Which means your point about static compilation was the decisive one. You were right that documenting it was the wrong answer, and it goes further than "inconvenient": in The new PR does exactly that: Your other review points are carried over: the command-object spec now submits only Leaving this thread open would mean nine inline comments anchored to code that no longer exists, so it is cleaner to review the new PR fresh — but the analysis in your review is what produced it, and it is linked from there. |
Fixes #16280
Problem
Groovy 5 changed runtime method selection for classes that implement
Map. For aStringsubscript key,DefaultGroovyMethods.putAt(Object, String, Object)(→setProperty) now wins overputAt(Map, K, V)(→put), andgetAt(Object, String)(→getProperty) overgetAt(Map, Object). BecauseGrailsParameterMapdeclaresgetIdentifier()andgetRequest()with no setters, those names became read-only properties rather than ordinary map keys:params['identifier'] = 'x'ReadOnlyPropertyExceptionparams['request'] = 'x'ReadOnlyPropertyExceptionparams['identifier']getIdentifier()→params.idparams['request']HttpServletRequestparams.identifier/params.requestGroovyPageAttributesis affected the same way:attrs['gspTagSyntaxCall'] = xsilently wrote the boolean field instead of the map.Fix
AbstractTypeConvertingMap— the shared base ofGrailsParameterMapandGroovyPageAttributes— declaresgetAt(String)/putAt(String, Object)and map-firstgetProperty/setProperty, so subscript and property access always address a map entry. This restores the Grails 7 rule.Declaring
getAt(Object)/putAt(Object, Object)does not work; DGM'sStringoverload remains the closer match. TheStringoverloads are what fix it, verified against both Groovy 4.0.30 and Groovy 5.0.6.metaClassis exempt from the property override so Groovy's own machinery keeps working. It is still readable as a map entry throughparams['metaClass'].getIdentifier()andgetRequest()are unchanged.getIdentifier()still reads only theidparameter — an earlier revision of this PR let a parameter namedidentifiertake precedence, which0093ab2reverted after review, becauseController.initializeCommandObject()feeds that value toType.get()when resolving a domain command object.getRequest()keeps itsHttpServletRequestreturn type; widening it toObjectwould break every caller and would let a submitted form field flow into framework code expecting a servlet request.Both names remain reachable as ordinary map entries through
params['identifier']andparams['request'], which is what the issue asked for.Also in this PR
grails-taglibhad nojunit-jupiter-engineon its test runtime classpath, soGroovyPageAttributesTests— the module's only JUnit 5 test — was never discovered. Added the engine; all tests in that module now run and pass.Documentation
upgrading80x.adoc§28.3, alongside the existing Groovy 5 behavior-change notes: the restored rule, a NOTE covering the static-compilation limitation on bothparamsandattrs, and the two deltas from Grails 7 (params.metaClass, and assignment to a setter-backed name writing a map entry instead of invoking the setter).controllersAndScopes.adoc— the everyday rule forparamsandattrsaccess.Testing
GrailsParameterMapTests: collision names via subscript and dot syntax; collisions arriving from the HTTP request;getIdentifier()reading onlyid;getRequest()unaffected; absent keys reading asnull;metaClassneither shadowed nor assignable; statically compiled access;GString/Integer/nullkeys and values;remove/containsKey; cloning;toQueryString; nested maps.TypeConvertingMapTests: 4 new tests at the level where the fix lives.GroovyPageAttributesTests: 2 new tests.Verified green:
grails-core,grails-web-common,grails-controllers,grails-web-mvc,grails-url-mappings,grails-gsp,grails-web-taglib,grails-taglib,grails-shell-cli.aggregateViolationsreports no Checkstyle, CodeNarc, PMD or SpotBugs issues.Opened as a draft to confirm CI is green before requesting review.