Skip to content

AbstractRequestMatcherRegistry#computeErrorMessage is invoked unnecessarily (can cause performance issues) #15714

Closed
@tugjg

Description

@tugjg

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 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()));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions