Describe the bug
Following the change made in
https://github.com/spring-projects/spring-security/commit/dab48d25b0e235fc7b345a13d14f9ef0cd284fd9#diff-1dcd43c70f929608b0d2d5914a309981a88a26786dcb373f65ba4c75b008c2f5L631
,AbstractRequestMatcherRegistry.DispatcherServletRequestMatcher#matches calls AbstractRequestMatcherRegistry#computeErrorMessage:
@Override
public boolean matches(HttpServletRequest request) {
<...>
Assert.notNull(registration, computeErrorMessage(this.servletContext.getServletRegistrations().values()));
<...>
}
The problem is that AbstractRequestMatcherRegistry#computeErrorMessage gets invoked everytime, even if registration is non-null. This can be expensive for applications that for whatever reason have a large number of ServletRegistrations.
Expected behavior
AbstractRequestMatcherRegistry.DispatcherServletRequestMatcher#matches should only invoke
AbstractRequestMatcherRegistry#computeErrorMessage if registration is null.
This can be achieved by using the Assert.nonNull method overload that takes a Supplier as the second argument:
Assert.notNull(registration, () -> computeErrorMessage(this.servletContext.getServletRegistrations().values()));
Comment From: tugjg
I left out the Steps To Reproduce/Sample, but can provide either of those if they're needed.