Skip to content

PathPattern#combine throws StringIndexOutOfBoundsExceptionΒ #34986

Closed

Description

@stefan-hasse

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

:)

Activity

  1. self-assigned this
    on Jun 3, 2025
  2. added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    on Jun 3, 2025
  3. changed the title [-]`PathPattern.combine(PathPattern)` throws `StringIndexOutOfBoundsException`[/-] [+]PathPattern#combine throws StringIndexOutOfBoundsException[/+] on Jun 3, 2025
  4. DhruvTheDev1 commented on Jun 3, 2025

    @DhruvTheDev1
    Contributor

    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.

  5. added and removed on Jun 4, 2025
  6. added this to the 6.2.8 milestone on Jun 4, 2025
  7. added a commit that references this issue on Jun 4, 2025
    4a46d95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions