Affects: 6.1.2+ (probably since the introduction of PathPatterns)


When you use a RedirectView with an URI that contains a path variable, and PathPatterns are enabled, then the variable value is missing.

This is due to the fact that the PathPattern codepath of AbstractUrlHandlerMapping is calling buildPathExposingHandler() with uriTemplateVariables parameter of null.

As a consequence no PathExposingHandlerInterceptor is added to the execution chain. The variable values are never parsed from the URI.

When RedirectView tries to access the variable values of the variables in the URI at replaceUriTemplateVariables() it throws an IllegalArgumentException.

When AntPatterns are used instead of PathPatterns, then the variable values are parsed and all is well.

@Configuration
public class TestMvConfiguration implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        String srcPath = "/some/path/{variable}/foo"; 
        String tgtPath = "/some/path/{variable}/bar";
        registry.addRedirectViewController(srcPath, tgtPath)
                .setStatusCode(HttpStatus.PERMANENT_REDIRECT);
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setPatternParser(new PathPatternParser());  // broken
//       configurer.setPathMatcher(new AntPathMatcher());      // works
    }

}