Situation
I've had the situation that a @Controller
was defined with @RequestMapping("/*")
to manage all request for that Dispatcher
(that already defined urlPatterns="/main/something/*"
to distinguish from other dispatcher).
Now, when the Dispatcher was initializing it was throwing StringIndexOutOfBoundsException
for a method in that Controller with a @GetMapping(value = "/x/{val}")
mapping defined.
*Root cause I could drill this down to PathPattern:combine ... also reproducible by adding this case to spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java:combine
assertThat(pathMatcher.combine("/*", "/x/y")).isEqualTo("/x/y");
Workaround
Currently I've solved it by defining the @Controller
with a @RequestMapping(/**)
for matching multiple path segments (as I assume it's intended).
Enhancement
I am unsure whether it's
- an enhancement request for a better exception OR
- a bug in combine
when instead of endsWithSeparatorWildcard
it's equal to the wildcard
:)
Comment From: DhruvTheDev1
So PathPattern.combine is expecting a pattern ending with /* but doesn't handle / properly which causes the StringIndexOutOfBoundsException - which is a runtime exception.
Hence, possibly a bug as it crashs when combining /* and /x/y.