Repository navigation
Fixed issue where GrailsExceptionResolver masks original exception with GrailsWebRequest cast failure. - #16396
Conversation
…th GrailsWebRequest cast failure.
…uest A DispatcherServlet other than the Grails one - the one MockMvc runs, for example - binds a plain ServletRequestAttributes over the GrailsWebRequest that GrailsWebRequestFilter bound. Guarding the casts alone left GrailsExceptionResolver forwarding to a controller error handler with a null GrailsWebRequest, so the original exception was still replaced. - URL mapping names, reverse mappings and the default URL creator find the GrailsWebRequest the filter stored on the request when the bound attributes are plain - Without one, a name closure is not called and resolves to null, and a map of HTTP methods is keyed by the method of the bound request. With no attributes bound at all, a closure is still called without a delegate - GrailsExceptionResolver forwards to a controller error handler only when the request has a GrailsWebRequest, and an error handler that cannot be resolved no longer replaces the exception being resolved: it is logged and the /error view renders the original exception - The default URL creator no longer prefixes URLs with "null" when there is no context path Fixes apache#16129
jdaugherty
left a comment
There was a problem hiding this comment.
Hi @ruthst00 & thank you picking this up. I reviewed this PR with an LLM and have noted it's feedback below for others to review. I believe all of these issues are addressed in my latest push:
Guarding the cast is the right direction, but as it stands only a view-mapped status code is fixed. A controller-mapped one still loses the original exception, now to an NPE instead of a ClassCastException. Details are inline. I checked this in a local checkout by running resolveException with real URL mappings, and by reverting each production hunk against the new specs.
Beyond the inline comments:
- The same unchecked
(GrailsWebRequest) RequestContextHolder.getRequestAttributes()cast is still inRegexUrlMapping.createURLInternaland twice inDefaultUrlCreator. Those run when the error view renders a link under the same plain attributes. Since the issue asks that this path stop assuming aGrailsWebRequest, it makes sense to route them through the same lookup in this PR.
| def resolver = new GrailsExceptionResolver() { | ||
|
|
||
| @Override | ||
| protected void forwardRequest(UrlMappingInfo forwarded, HttpServletRequest req, |
There was a problem hiding this comment.
Overriding forwardRequest hides the part of this bug the PR doesn't fix yet (commenting here because GrailsExceptionResolver isn't in the diff). The real forwardRequest calls info.configure(WebUtils.retrieveGrailsWebRequest()), and retrieveGrailsWebRequest() returns null when the bound attributes aren't a GrailsWebRequest. populateParamsForMapping(null) then throws an NPE, which resolveViewOrForward wraps in a GrailsRuntimeException. So the original exception is still lost.
I ran resolveException against real mappings built by DefaultUrlMappingEvaluator, with a plain ServletRequestAttributes bound:
| status mapping | 8.0.x |
this PR |
|---|---|---|
"500"(view: '/error') |
ClassCastException |
resolves (view set, status 500) |
"500"(controller: 'errors', action: 'serverError') |
ClassCastException |
GrailsRuntimeException → NPE in populateParamsForMapping |
"500"(controller: { 'errors' }, action: 'serverError') |
ClassCastException |
GrailsRuntimeException → UrlMappingException |
Controller-mapped error handlers are common, so the resolver needs a fix as well. For the MockMvc case in the issue, GrailsWebRequestFilter has already stored the GrailsWebRequest on the request before the dispatcher rebinds plain attributes over it. So info.configure(GrailsWebRequest.lookup(request)) finds it; with just that change, the controller mapping forwards to /errors/serverError. When there's no GrailsWebRequest at all (the issue's direct resolveException reproduction), the forward can't be configured. Returning mv without forwarding would let the original exception reach the default error view. UrlMappingUtils.forwardRequestForUrlMappingInfo also dereferences GrailsWebRequest.lookup(request) without a null check, so that path needs the same guard.
| RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, new MockHttpServletResponse())) | ||
|
|
||
| and: 'a UrlMappingInfo whose getControllerName() triggers a closure-based name resolution' | ||
| def info = Mock(UrlMappingInfo) |
There was a problem hiding this comment.
This test passes with both production changes reverted (I put AbstractUrlMappingInfo and DefaultUrlMappingInfo back to 8.0.x and it stays green). UrlMappingInfo and UrlMappingsHolder are mocks, so nothing reads RequestContextHolder, and getControllerName() is stubbed to return 'errors'. The closure-based name resolution described in the and: label never happens.
Could this build real mappings with DefaultUrlMappingEvaluator and DefaultUrlMappingsHolder, and go through resolveException (the entry point from the issue) without overriding forwardRequest? Cover both a view mapping and a controller mapping, and assert that the returned ModelAndView's exception entry wraps the original exception. That version fails today for the controller mapping (see the comment on forwardRequest) and will pin the fix once it's in.
| GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes(); | ||
| org.springframework.web.context.request.RequestAttributes attrs = | ||
| RequestContextHolder.getRequestAttributes(); | ||
| GrailsWebRequest webRequest = attrs instanceof GrailsWebRequest ? (GrailsWebRequest) attrs : null; |
There was a problem hiding this comment.
This is the frame from the issue's stack trace (getNamespace() → evaluateNameForValue(Object)), but no test fails if it's reverted. With only this hunk put back to the unconditional cast, all of AbstractUrlMappingInfoSafeCastSpec and GrailsExceptionResolverSpec still pass. The specs go through either getActionName(), which calls the two-arg overload directly, or a String controller name, which returns before the cast. A spec calling getNamespace() / getViewName() / getId() on a mapping with no namespace, while plain attributes are bound, would cover it.
Also, GrailsWebRequest.lookup() already does exactly this instanceof check. Use it, or the helper suggested on the closure branch below, here and in DefaultUrlMappingInfo.getActionName() instead of two inline copies with a fully-qualified RequestAttributes.
|
|
||
| String name; | ||
| if (value instanceof Closure) { | ||
| if (webRequest == null) { |
There was a problem hiding this comment.
Returning null here changes more than the cast:
- When nothing is bound, the closure used to run anyway, with a
nulldelegate. A closure that doesn't touch the request, such asaction: { 'show' }, resolved toshowon8.0.xand resolves tonullnow. - A controller name that comes back
nullmakesgetControllerName()throwUrlMappingException. So a status mapping with a closure controller still masks the original exception; theClassCastExceptionjust becomes aUrlMappingException(last row of the table on theforwardRequestcomment).
In the MockMvc case from the issue the GrailsWebRequest still exists: GrailsWebRequestFilter stored it on the request before the dispatcher bound plain attributes over it. When the bound attributes are a ServletRequestAttributes, GrailsWebRequest.lookup(((ServletRequestAttributes) attrs).getRequest()) recovers it, and the closure keeps evaluating against the real request. null would then only be returned when no GrailsWebRequest exists anywhere. A private helper for that lookup would also replace the inline copies in both files.
| name = result != null ? result.toString() : null; | ||
| } | ||
| else if (value instanceof Map) { | ||
| if (webRequest == null) { |
There was a problem hiding this comment.
Selecting by HTTP method doesn't need a GrailsWebRequest: HiddenHttpMethod.effectiveMethod takes the HttpServletRequest, which a plain ServletRequestAttributes already has. As written, action: [GET: 'show', POST: 'save'] quietly resolves to null whenever the bound attributes aren't Grails'. Taking the request from the bound ServletRequestAttributes would keep this branch working. No spec covers the Map branch yet.
| actionName == null | ||
| } | ||
|
|
||
| void 'getActionName does not throw ClassCastException when RequestContextHolder holds a plain ServletRequestAttributes'() { |
There was a problem hiding this comment.
This feature is identical to the one above: same mapping, same bound attributes, same info.actionName call. The one above is named for evaluateNameForValue(Object) but never reaches it. Also in this spec:
- The empty-holder feature below is named for
ClassCastException, but on8.0.xit failed with an NPE (casting a null holder is fine). - The static controller-name feature passes on
8.0.x, because aStringname returns before the cast.
A data-driven feature would cover the one-arg path this spec is missing. Run it over the public getters (namespace, controllerName, actionName, viewName, id), crossed with the holder state (GrailsWebRequest, plain ServletRequestAttributes, nothing bound) and the value shape (String, closure, method Map).
| * {@link ServletRequestAttributes} instead of a {@link org.grails.web.servlet.mvc.GrailsWebRequest}. | ||
| * | ||
| * <p>This scenario arises when {@link org.grails.web.errors.GrailsExceptionResolver} resolves an | ||
| * exception: Spring's {@code DispatcherServlet} may have bound a {@code ServletRequestAttributes} |
There was a problem hiding this comment.
This isn't quite how the plain attributes get there. In a Grails app, GrailsDispatcherServlet.buildRequestAttributes replaces a plain ServletRequestAttributes with a GrailsWebRequest, so exception resolution under Grails' own dispatcher always sees one. The plain attributes come either from a non-Grails dispatcher rebinding over the GrailsWebRequest that GrailsWebRequestFilter set (MockMvc's TestDispatcherServlet, as in the issue), or from code calling the resolver directly. Could the Javadoc, and the root-cause section of the PR description, say that?
|
@matrei @codeconsole can one of you review this too please? I believe I've fixed all of the issues I found with it. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16396 +/- ##
==================================================
+ Coverage 57.4998% 57.9654% +0.4656%
- Complexity 22590 22969 +379
==================================================
Files 2129 2135 +6
Lines 103863 105149 +1286
Branches 18651 18972 +321
==================================================
+ Hits 59721 60950 +1229
+ Misses 35871 35823 -48
- Partials 8271 8376 +105
🚀 New features to boost your workflow:
|
…ing the uncovered and partially covered branches in `GrailsExceptionResolver.java` identified from the Codecov PR apache#16396 report. All 45 tests pass with no style violations.
matrei
left a comment
There was a problem hiding this comment.
Reviewed at head 09834160c2 (base 8.0.x, merge base a441334507). It merges cleanly into the current 8.0.x at 0dab8a7263.
Thanks for sticking with this, @ruthst00. @jdaugherty's push (912be076d0) addressed his earlier review. I read the production changes again and they look good to me: the unchecked cast is gone from the name lookups and both URL creators, the resolver keeps the original exception when the error handler can't be resolved or forwarded to, and the tests build real mappings and go through resolveException. Most of my comments are about what has been added since then, c49632a0d9 and the merge commit.
Run locally at the head:
| Module | Tests | Result |
|---|---|---|
grails-web-mvc |
78 | pass |
grails-web-url-mappings |
279 | pass |
1. Please drop the geb.env change in gradle/functional-test-config.gradle
c49632a0d9 adds systemProperty('geb.env', 'test') for every Test task in every module that applies this script. It has nothing to do with #16129. None of the GebConfig.groovy files in the repository have an environments { test { ... } } block, so on CI it does nothing. If it was needed to get Geb tests running on your machine, please keep it local (for example in ~/.gradle/init.d) or open an issue describing what failed, so we can fix it properly.
2. Please move the 20 coverage tests into a separate PR
The tests added in c49632a0d9 cover parts of GrailsExceptionResolver that this PR doesn't change: log message formatting, findWrappedException, determineUri, isExcludedRequestParameter, the log flag caching and createStackFilterer. Tests for existing behaviour are welcome, but they belong in their own PR. This one should stay focused on the fix for #16129. Codecov's patch coverage only counts the lines this PR changes, and James's tests already cover those.
If you open the follow-up PR, please also look at these points:
resolveViewOrForward skips forward when response is already committeddoesn't test what its name says. NoGrailsWebRequestis bound, soresolveViewOrForwardreturns at the newGrailsWebRequest.lookup(request) == nullcheck before it reachesresponse.isCommitted(). I changedresponse.committed = truetofalseand the spec still passed, 60 of 60. To test the committed branch, bind aGrailsWebRequestthe way the#handler/#attributesfeatures do. Also assert something more specific thanresult != null, such as the returnedModelAndViewstill holding the original exception.- Test through the public behaviour, not the implementation.
resolveLogFlags is idempotent — config is consulted only oncecounts calls into a private cache, andresolveLogFlags reads false for all flags…is named after a private method. Both will break on a harmless refactor. TheisExcludedRequestParameteranddetermineUrifeatures call protected helpers directly. What users see is the logged message, so assert ongetRequestLogMessage(...)output instead. The existinggetRequestLogMessage masks excluded request parameters case-insensitivelyfeature is a good model. - Some features repeat existing ones. The case-insensitive exclusion match is already covered by
getRequestLogMessage masks excluded request parameters case-insensitively. ThecreateStackFiltererfallback is already covered by the threefalls back to building from configfeatures. The new feature adds only the catch branch. - Style: use imports instead of the fully qualified
org.grails.web.util.WebUtilsandorg.grails.core.exceptions.GrailsRuntimeException, and keep the new imports in order with the others (InvokerInvocationExceptionandControllerExecutionExceptionare out of place).
3. Update the PR description
The description still describes the first commit. AbstractUrlMappingInfoSafeCastSpec no longer exists (it was replaced by UrlMappingInfoRequestAttributesSpec), and the description doesn't mention the changes to GrailsExceptionResolver, UrlMappingUtils, DefaultUrlCreator, RegexUrlMapping or the guide. The root cause section should also say where the plain attributes actually come from, as James asked in his review: a dispatcher other than the Grails one binding them over the GrailsWebRequest (as MockMvc does), or code calling the resolver directly. The first paragraph of the 912be076d0 commit message puts it well. The title is also cut off after "…with"; please complete it.
4. Clean up the history
09834160c2 merges the branch's own remote copy into itself, and PRs are merged here without squashing, so that merge commit would end up on 8.0.x. After removing c49632a0d9, please drop the merge commit too, for example by resetting the branch to 912be076d0 and force-pushing. The remaining history is then just the original fix followed by James's commit.
With these changes, I'm happy with it.
|
One more thing, about the target branch. This bug is also on However, it can't just be retargeted. Applying That leaves two options:
I lean toward 2, since most of the rework would be in the resolver changes. @jdaugherty, since those are your changes, which do you prefer? |
0983416 to
912be07
Compare
✅ All tests passed ✅🏷️ Commit: 912be07 Learn more about TestLens at testlens.app/docs. |
|
@matrei, thank you for your thorough analysis of my latest changes and giving me clear instructions for backing out of the mess I made trying to address issues in the CodeCov report :o) As instructed, I reset the PR branch to 912be07 which dropped the last two commits: I then and force-pushed to set the history back to the original fix followed by @jdaugherty's commit. Also updated the PR description to encompass all changes in the two remaining commits. |
|
@matrei let's keep this focused on 8.0.x and we can backport as needed. I'm going to take another pass at this and look to see if this can be merged. |
matrei
left a comment
There was a problem hiding this comment.
Reviewed at head 912be076d0 (base 8.0.x, merge base a441334507). It merges cleanly into the current 8.0.x at 7ce779e2e7, and 8.0.x hasn't touched any of the changed files since the merge base.
Thanks, @ruthst00, that's exactly what I was after. All the points from my last review are addressed:
- The
geb.envchange ingradle/functional-test-config.gradleis gone. - The coverage tests for unchanged
GrailsExceptionResolverbehaviour are gone. The remaining tests cover the fix only. - The title is complete, and the description now covers every changed file, including where the plain attributes come from.
- The history is the original fix followed by @jdaugherty's commit, with no merge commit.
The production code is unchanged from 912be076d0, which I had already read and was happy with. I also checked that no unchecked (GrailsWebRequest) RequestContextHolder.getRequestAttributes() cast is left anywhere in the repository.
Run locally on the PR merged into 7ce779e2e7, without the build cache:
| Module | Tests | Result |
|---|---|---|
grails-web-mvc (35 in GrailsExceptionResolverSpec) |
53 | pass |
grails-web-url-mappings (20 in UrlMappingInfoRequestAttributesSpec) |
279 | pass |
Checkstyle (main) and CodeNarc (test) for both modules |
clean |
On the target branch: agreed, @jdaugherty, let's merge this on 8.0.x and do the 7.0.x backport as a separate PR afterwards.
Approving.
|
Thank you @ruthst00 for your contribution and patience! |
|
Thank you, @jdaugherty and @matrei for your careful review and guidance! Couldn't have done it without you :-) |
…-7.0.x Backport #16396 to 7.0.x: resolve error handlers and mapping names without a bound GrailsWebRequest
…uest Backport of apache#16396 to 7.0.x. A DispatcherServlet other than the Grails one - the one MockMvc runs, for example - binds a plain ServletRequestAttributes over the GrailsWebRequest that GrailsWebRequestFilter bound. The casts to GrailsWebRequest in the URL mapping layer then threw a ClassCastException, which GrailsExceptionResolver reported in place of the exception it was resolving. - URL mapping names, the names a mapping captures from the URI ($controller, $action, ...), reverse mappings and the default URL creator find the GrailsWebRequest the filter stored on the request when the bound attributes are plain - Without one, a name closure is not called and resolves to null, and a map of HTTP methods is keyed by the method of the bound request. With no attributes bound at all, a closure is still called without a delegate - GrailsExceptionResolver forwards to a controller error handler only when the request has a GrailsWebRequest, and an error handler that cannot be resolved no longer replaces the exception being resolved: it is logged and the /error view renders the original exception - The default URL creator no longer prefixes URLs with "null" when there is no context path Fixes apache#16129 Co-authored-by: ruthes00 <ruthes00@gmail.com>
Description
Root Cause
Two unconditional casts to
GrailsWebRequestin the URL mapping layer would throwClassCastExceptionwhen Spring'sRequestContextHolderheld a plainServletRequestAttributes(not aGrailsWebRequest). This happens during exception resolution when the Grails filter hasn't had a chance to upgrade the request attributes. TheClassCastExceptionthen replaced the original application exception inGrailsExceptionResolver, masking the real error.A
DispatcherServletother than the Grails one - the one MockMvc runs, for example - binds a plainServletRequestAttributesover theGrailsWebRequestthatGrailsWebRequestFilterbound. Guarding the casts alone leftGrailsExceptionResolverforwarding to a controller error handler with a nullGrailsWebRequest, so the original exception was still replaced.Changes Made
1.
grails-doc/src/en/guide/theWebLayer/urlmappings/mappingToResponseCodes.adocAdds a new
NOTEadmonition block just before the existingWARNINGabout error handler stack overflows.2.
grails-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.javaChanges:
New import:
GrailsWebRequestis now imported directly.resolveViewOrForward()— two-phase error handling with defensive guards:try/catch(RuntimeException): The call tomatchStatusCode()and the subsequent parameter merging are now wrapped in a try/catch. If the mapping resolution itself throws (e.g., a closure-basedcontroller:mapping that reads Grails request state that wasn't initialized), the exception is logged as an error and the method returns the defaultmv(the/errorview with the original exception). This prevents the mapping failure from replacing the original exception.mapsToView/mapsToControllerbooleans are computed inside the try block and used in the second phase, cleanly separating resolution from dispatch.GrailsWebRequestbefore forwarding to a controller: Before attempting to forward to an error-handling controller, the code now checksGrailsWebRequest.lookup(request) == null. If there is noGrailsWebRequest(e.g., a MockMvc test without Grails filters), it logs a warning and returns the defaultmvinstead of crashing.forwardRequest()— request-scoped lookup instead of thread-local:Changed from
WebUtils.retrieveGrailsWebRequest()(which reads the thread-localRequestContextHolder) toGrailsWebRequest.lookup(request)(which reads theGrailsWebRequeststored on the request object itself). This correctly finds theGrailsWebRequesteven when a non-GrailsDispatcherServlethas overwritten the thread-local with plainServletRequestAttributes.3.
grails-web-mvc/src/test/groovy/org/grails/web/errors/GrailsExceptionResolverSpec.groovyChanges:
New shared infrastructure:
GRAILS,PLAIN_OVER_GRAILS,PLAIN,NOTHING) describe the four possible request-attribute binding states under test.MockServletContextandStaticWebApplicationContextfield, with acleanup()method that resetsRequestContextHolderand closes the web context after each feature.Two existing tests fixed: The two pre-existing tests that forward to a controller (
resolveViewOrForwardwith a controller mapping) now callbind(GRAILS, request, response)to set up theGrailsWebRequestthat the fixed code now requires before forwarding.Three new
@Issue('#16129')data-driven feature methods:"an error handler mapped to #handler is forwarded to with #attributes bound"— Verifies the happy path: when aGrailsWebRequestis available (either directly bound or stored on the request under plain attributes), the error handler controller is successfully forwarded to, the response'sforwardedUrlis set, and the original exception is preserved as the cause of the wrapped exception on the request attribute.Covers: static controller name, closure-based controller name, and HTTP-method-map action — all with
GRAILSorPLAIN_OVER_GRAILSattributes."the default error view renders the exception when #handler cannot be forwarded to with #attributes bound"— Verifies the graceful degradation path: when there is noGrailsWebRequest(only plain attributes or nothing), or when the mapping closure itself throws, the result is the/errorview name, no forward URL, and the original exception is preserved in the model. Covers all the failure scenarios including a broken mapping closure."an error handler mapped to a view renders with #attributes bound"— Verifies that view-mapped error handlers (not controller-mapped) work correctly under all four attribute states (GRAILS,PLAIN_OVER_GRAILS,PLAIN,NOTHING), since view resolution doesn't require aGrailsWebRequest.New helper methods:
resolverFor(Closure mappings, boolean controllerMappings)— builds a fully wiredGrailsExceptionResolverwith a realDefaultUrlMappingsHolder, optionalGrailsControllerUrlMappingswrapper, a stubViewResolver, and aStaticWebApplicationContext.bind(String attributes, request, response)— sets up the thread-local request attributes in one of the four states.4.
grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/UrlMappingUtils.javaChange: Adds a new package-private static method
lookupWebRequest().This is the central fix for the URL mappings layer. Instead of casting
RequestContextHolder.getRequestAttributes()directly toGrailsWebRequest(which fails when MockMvc'sDispatcherServlethas overwritten the thread-local with a plainServletRequestAttributes), this method:GrailsWebRequest.ServletRequestAttributes, falls back toGrailsWebRequest.lookup(request)— reading theGrailsWebRequestthatGrailsWebRequestFilterstored on the request object.nullif neither applies.All other URL mapping classes are updated to call this method instead of doing the raw cast themselves.
5.
grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/AbstractUrlMappingInfo.javaChanges:
evaluateName()(the no-arg overload): Now callsUrlMappingUtils.lookupWebRequest()instead of castingRequestContextHolder.getRequestAttributes()directly.evaluateNameForValue(Object value, GrailsWebRequest webRequest)— improved Javadoc and two new guards:webRequestisnullbut there are request attributes bound (meaning a non-Grails dispatcher is active withoutGrailsWebRequestFilter), the closure is not called andnullis returned. This prevents the closure from running without its expected Grails delegate and potentially throwing or returning garbage. Previously, the closure would be called with anulldelegate.webRequestisnull, the code now falls back tocurrentRequest()(a new private helper that extracts theHttpServletRequestfrom a plainServletRequestAttributes). If there is no request at all,nullis returned instead of throwing aNullPointerException.New private helper
currentRequest(): Uses a Java 16+ pattern-matchinginstanceofto safely extract theHttpServletRequestfromServletRequestAttributes, returningnullif the bound attributes are not servlet-based.6.
grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingInfo.javaChanges:
RequestContextHolderandGrailsWebRequest(the logic has moved toAbstractUrlMappingInfoandUrlMappingUtils).getActionName()now calls the no-argevaluateNameForValue(actionName)(inherited fromAbstractUrlMappingInfo) instead of manually castingRequestContextHolder.getRequestAttributes()toGrailsWebRequestand passing it in. Also switches fromvarto explicitStringtype for clarity.7.
grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlCreator.javaChanges:
RequestContextHoldercasts replaced withUrlMappingUtils.lookupWebRequest()increateURL(Map, String)andcreateURLInternal(...). This ensures the context path is correctly read from theGrailsWebRequesteven when MockMvc's dispatcher has overwritten the thread-local.includeContextPathbranch now first fetches the context path into a local variable and only appends it if it is non-null. This avoids appending a null/empty string when noGrailsWebRequestis available.import org.springframework.web.context.request.RequestContextHolder.8.
grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/RegexUrlMapping.javaChange: In the URL creation path that prepends the context path, the direct
RequestContextHoldercast toGrailsWebRequestis replaced withUrlMappingUtils.lookupWebRequest(). Removes the now-unusedimport org.springframework.web.context.request.RequestContextHolder.9.
grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/UrlMappingInfoRequestAttributesSpec.groovyChange: A brand-new Spock specification that exhaustively tests how URL mapping info resolves names and creates URLs under all four request-attribute binding states.
Feature methods:
'names a mapping states resolve with #attributes bound'— Static controller/action/view/URI names resolve correctly regardless of which attributes are bound.'a name closure reads the GrailsWebRequest with #attributes bound'— A closure-based action name (e.g.,action: { params.section }) correctly reads request parameters when aGrailsWebRequestis available (directly or via fallback).'a name closure is not called when the bound attributes have no GrailsWebRequest'— When only plainServletRequestAttributesare bound (noGrailsWebRequest), closures are not invoked and returnnullsafely.'a name closure is called without a delegate when no request attributes are bound'— When nothing is bound, a closure that doesn't need a delegate (e.g.,{ 'show' }) still works.'a map of HTTP methods selects the name for the request method with #attributes bound'— HTTP-method maps work withGRAILS,PLAIN_OVER_GRAILS, andPLAINattributes; returnnullwhen nothing is bound.'a mapping creates its URL with the context path of the GrailsWebRequest with #attributes bound'— Context path is included in generated URLs only when aGrailsWebRequestis available.'the default URL creator uses the context path of the GrailsWebRequest with #attributes bound'— Same context-path behavior verified forDefaultUrlCreatordirectly.Fixes #16129
Generated with Claude Sonnet 4.6 via Cline API Provider inside IntelliJ 2025.3.3
Contributor Checklist
Please review the following checklist before submitting your pull request. Pull requests that do not meet these requirements may be closed without review.
Issue and Scope
7.0.x): Bug fixes only. No new features or API changes.7.1.x): New features are welcome, but breaking existing APIs must be avoided.8.0.x): Reserved for major changes. Breaking API changes are permitted.Code Quality
./gradlew build --rerun-tasks../gradlew codeStyleand resolved any violations. See Code Style for details.Licensing and Attribution
Documentation