Cannot invoke org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns because this.condition is null
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The error Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null is a NullPointerException that occurs in Spring MVC when the request mapping infrastructure encounters a handler method whose URL pattern condition has not been properly initialized. This is most commonly caused by version incompatibilities between Spring Boot, Spring Framework, and third-party libraries like Springfox/Swagger or Spring Cloud.
Common Causes
1. Springfox Swagger Incompatibility (Most Common)
The most frequent cause is using Springfox (Swagger 2.x) with Spring Boot 2.6+ or Spring Boot 3.x. Spring Boot 2.6 changed the default path matching strategy from AntPathMatcher to PathPatternParser, which Springfox does not support:
Quick Fix: Add to application.properties:
Better Fix: Migrate from Springfox to SpringDoc OpenAPI, which supports the new path matching:
2. Spring Boot 3.x with Legacy Libraries
Spring Boot 3.x (Spring Framework 6) requires Jakarta EE instead of javax. Libraries that still use javax servlets cause initialization failures:
3. Custom RequestMappingHandlerMapping
If you have a custom RequestMappingHandlerMapping that does not properly initialize conditions:
4. Actuator Endpoint Conflicts
Spring Boot Actuator endpoints can trigger this when combined with certain path matching configurations:
Step-by-Step Diagnosis
Step 1: Identify the Conflicting Library
Check your dependencies for known incompatible libraries:
Step 2: Check Spring Boot Version
| Spring Boot | Default Path Matching | Springfox Compatible? |
| 2.5.x and below | ant_path_matcher | Yes |
| 2.6.x - 2.7.x | path_pattern_parser | No (without config) |
| 3.x | path_pattern_parser | No (use SpringDoc 2.x) |
Step 3: Check the Full Stack Trace
The stack trace will show which handler is causing the issue:
If springfox appears in the trace, it confirms the Springfox incompatibility.
Migration from Springfox to SpringDoc
Remove Springfox Configuration
Add SpringDoc
SpringDoc serves Swagger UI at /swagger-ui.html and the OpenAPI spec at /v3/api-docs.
Common Pitfalls
- Partial fix: Setting
ant_path_matcherfixes the error but opts out of Spring Boot's improved path matching. This is a temporary workaround — migrate to SpringDoc for a permanent fix. - Multiple Swagger dependencies: Having both Springfox and SpringDoc on the classpath causes conflicts. Remove one completely, including transitive dependencies.
- Spring Security interaction: If Spring Security is configured, ensure Swagger/OpenAPI paths are permitted:
- Spring Cloud Gateway: Spring Cloud Gateway uses a reactive stack and has its own path matching. Ensure you use
springdoc-openapi-starter-webflux-uiinstead of the WebMVC variant.
Summary
- This error is most commonly caused by Springfox (Swagger 2.x) incompatibility with Spring Boot 2.6+
- Quick fix: set
spring.mvc.pathmatch.matching-strategy=ant_path_matcher - Permanent fix: migrate from Springfox to SpringDoc OpenAPI (
springdoc-openapi-starter-webmvc-ui) - For Spring Boot 3.x, use SpringDoc 2.x (Jakarta EE compatible)
- Always check the stack trace to identify which library triggers the null condition
Related reading
- Cannot load driver class org.h2.Driver in spring boot application
- Cannot refer to a non-final variable inside an inner class defined in a different method
- Cannot resolve method 'antMatchers' in AuthorizationManagerRequestMatcherRegistry
- Cannot resolve symbol 'AppCompatActivity
- Cannot launch docker desktop for mac
- Cannot launch SparkPi example on Kubernetes Spark 2.4.0
- Cannot Resolve Symbol SpringBootApplication - IntelliJ DEA
- Can't Autowire Repository annotated interface in Spring Boot

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.