Skip to content

Commit b0dc0f8

Browse files
committed
Fix binary compatibility issue with interceptors. Fixes #9793
1 parent ea117e3 commit b0dc0f8

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

grails-plugin-interceptors/src/main/groovy/grails/artefact/Interceptor.groovy

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
6464
/**
6565
* The matchers defined by this interceptor
6666
*/
67-
Collection<Matcher> matchers = new ConcurrentLinkedQueue<>()
67+
final Collection<Matcher> matchers = new ConcurrentLinkedQueue<>()
6868

6969
/**
7070
* @return Whether the current interceptor does match
@@ -76,6 +76,14 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
7676
* @return Whether the current interceptor does match
7777
*/
7878
boolean doesMatch(HttpServletRequest request) {
79+
def allMatchers = matchers
80+
if(allMatchers.isEmpty()) {
81+
// default to map just the controller by convention
82+
def matcher = new UrlMappingMatcher(this)
83+
matcher.matches(controller:Pattern.compile(GrailsNameUtils.getLogicalPropertyName(getClass().simpleName, InterceptorArtefactHandler.TYPE)))
84+
allMatchers << matcher
85+
}
86+
7987
String interceptorMatchKey = "${getClass().name}${InterceptorArtefactHandler.MATCH_SUFFIX}"
8088
def existing = request.getAttribute(interceptorMatchKey)
8189
if(existing != null && !WebUtils.isForward(request) && !WebUtils.isInclude(request)) {
@@ -88,7 +96,7 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
8896
def matchedInfo = request.getAttribute(UrlMappingsHandlerMapping.MATCHED_REQUEST)
8997
UrlMappingInfo grailsMappingInfo = (UrlMappingInfo)matchedInfo
9098

91-
for(Matcher matcher in matchers) {
99+
for(Matcher matcher in allMatchers) {
92100
if(matcher.doesMatch(uri, grailsMappingInfo)) {
93101
request.setAttribute(interceptorMatchKey, Boolean.TRUE)
94102
return true
@@ -263,17 +271,4 @@ trait Interceptor implements ResponseRenderer, ResponseRedirector, RequestForwar
263271
}
264272
}
265273

266-
/**
267-
* Registers the default match strategy if non has been registered
268-
*/
269-
@Autowired
270-
void setGrailsApplication(GrailsApplication grailsApplication) {
271-
if(matchers.isEmpty()) {
272-
// default to map just the controller by convention
273-
def matcher = new UrlMappingMatcher(this)
274-
matcher.matches(controller:Pattern.compile(GrailsNameUtils.getLogicalPropertyName(getClass().simpleName, InterceptorArtefactHandler.TYPE)))
275-
matchers << matcher
276-
}
277-
278-
}
279274
}

grails-plugin-interceptors/src/test/groovy/grails/artefact/InterceptorSpec.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class InterceptorSpec extends Specification {
3939
void "Test the default interceptor mappings"() {
4040
given:"A test interceptor"
4141
def i = new TestInterceptor()
42-
i.setGrailsApplication(null)
4342
def webRequest = GrailsWebMockUtil.bindMockWebRequest()
4443
HttpServletRequest request = webRequest.request
4544
when:"The current request is for a controller called test"

0 commit comments

Comments
 (0)