Address potential NullPointerException when calling Collection#contains

This commit is contained in:
Chris Eager
2024-03-07 15:48:25 -06:00
committed by Chris Eager
parent 7d364ca7ce
commit 2dc0ea2b89
2 changed files with 6 additions and 7 deletions

View File

@@ -160,12 +160,11 @@ public class MetricsHttpChannelListener implements HttpChannel.Listener, Contain
private RequestInfo getRequestInfo(Request request) {
final String path = Optional.ofNullable(request.getAttribute(URI_INFO_PROPERTY_NAME))
.map(attr -> UriInfoUtil.getPathTemplate((ExtendedUriInfo) attr))
.orElseGet(() -> {
if (servletPaths.contains(request.getPathInfo())) {
return request.getPathInfo();
}
return "unknown";
});
.orElseGet(() ->
Optional.ofNullable(request.getPathInfo())
.filter(servletPaths::contains)
.orElse("unknown")
);
final String method = Optional.ofNullable(request.getMethod()).orElse("unknown");
// Response cannot be null, but its status might not always reflect an actual response status, since it gets
// initialized to 200