Description
Describe the bug
Following the change made in
dab48d2#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 ServletRegistration
s.
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()));