sbglasius commented on PR #16281:
URL: https://github.com/apache/grails-core/pull/16281#issuecomment-5494506606

   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 
`@CompileStatic` with Groovy 5:
   
   | Expression | Result |
   |---|---|
   | `params['identifier'] = v` | ✅ writes the map entry |
   | `params['identifier']` | ✅ reads the map entry |
   | `params['request']` | ✅ reads the map entry |
   | `params['request'] = v` | ❌ compile error — `Cannot assign value of type 
java.lang.String to variable of type jakarta.servlet.http.HttpServletRequest` |
   | `params.identifier = v` | ❌ compile error — `Cannot set read-only 
property: identifier` |
   | `params.identifier` | ❌ `getIdentifier()` |
   | `params.request` | ❌ `getRequest()` |
   
   So the subscript *read* is fine statically for both names — it is the 
subscript *write* for `request` that also fails, which the finding did not 
mention. Worth having in the docs since that is the form people would reach for 
as the workaround.
   
   I went with documenting rather than chasing the implementation. Covering 
static compilation would mean removing `getRequest()`/`getIdentifier()` or 
widening their return types, which is the API break that was already rejected 
earlier in this PR.
   
   Changes:
   
   - `upgrading80x.adoc` §28.3 no longer claims the rule holds unconditionally 
— it now says "in dynamically compiled Groovy" and carries a `NOTE` with the 
exact compile errors and the portable workaround: subscript to read, 
`params.put(name, value)` to write.
   - `controllersAndScopes.adoc` carries the same qualification.
   - New `GrailsParameterMapTests > 
testStaticCompilationBindsPropertySyntaxToTheAccessor`, a `@CompileStatic` 
method pinning the statically compiled behaviour, including that 
`params.put('request', v)` is the form that works. The two compile errors 
cannot be asserted in a test, so they live in the docs.
   
   Re-verified: `:grails-web-common:test`, `:grails-core:test`, 
`:grails-taglib:test`, `:grails-test-suite-web:test`, 
`:grails-controllers:test` (all `--rerun-tasks`), `:grails-web-common:codeStyle 
--rerun-tasks`, and `aggregateViolations` clean on all four analysers.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to