diff --git a/servlet-core/src/main/java/io/micronaut/servlet/http/ServletHttpHandler.java b/servlet-core/src/main/java/io/micronaut/servlet/http/ServletHttpHandler.java index 2e1db40d1..9f055eef8 100644 --- a/servlet-core/src/main/java/io/micronaut/servlet/http/ServletHttpHandler.java +++ b/servlet-core/src/main/java/io/micronaut/servlet/http/ServletHttpHandler.java @@ -215,11 +215,16 @@ public void service(ServletExchange exchange) { if (exchange.getRequest().isAsyncSupported()) { exchange.getRequest().executeAsync(asyncExecution -> { try (PropagatedContext.Scope ignore = PropagatedContext.getOrEmpty().plus(new ServerHttpRequestContext(req)).propagate()) { - lc.handleNormal(req) - .onComplete((response, throwable) -> onComplete(exchange, req, response.toMutableResponse(), throwable, httpResponse -> { - asyncExecution.complete(); - requestTerminated.accept(httpResponse); - })); + lc.handleNormal(req).onComplete((response, throwable) -> onComplete( + exchange, + req, + response == null ? null : response.toMutableResponse(), + throwable, + httpResponse -> { + asyncExecution.complete(); + requestTerminated.accept(httpResponse); + } + )); } }); } else { @@ -228,7 +233,13 @@ public void service(ServletExchange exchange) { lc.handleNormal(req) .onComplete((response, throwable) -> { try { - onComplete(exchange, req, response.toMutableResponse(), throwable, requestTerminated); + onComplete( + exchange, + req, + response == null ? null : response.toMutableResponse(), + throwable, + requestTerminated + ); } finally { termination.complete(null); }