From 5dc715119112e6f71c65f7153de8304b35d36921 Mon Sep 17 00:00:00 2001 From: JacobOJ Date: Tue, 19 Nov 2024 14:34:39 +0100 Subject: [PATCH] Fix NullPointerException that would occur when WebApplicationException was thrown with an unassigned Http Status Code (#443) Co-authored-by: JacobOJ --- .../resteasy/problem/JaxRsMappersIT.java | 14 ++++++++++++++ .../jaxrs/WebApplicationExceptionMapper.java | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/integration-test/src/test/java/io/quarkiverse/resteasy/problem/JaxRsMappersIT.java b/integration-test/src/test/java/io/quarkiverse/resteasy/problem/JaxRsMappersIT.java index 361ad2c..7f7c3e7 100644 --- a/integration-test/src/test/java/io/quarkiverse/resteasy/problem/JaxRsMappersIT.java +++ b/integration-test/src/test/java/io/quarkiverse/resteasy/problem/JaxRsMappersIT.java @@ -6,6 +6,7 @@ import static jakarta.ws.rs.core.Response.Status.NOT_FOUND; import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.equalToIgnoringCase; import static org.hamcrest.Matchers.nullValue; import io.quarkus.test.junit.QuarkusTest; @@ -38,6 +39,19 @@ void webApplicationExceptionShouldReturnGivenStatus(int status) { .body("stacktrace", nullValue()); } + @ParameterizedTest(name = "http status: {0}") + @ValueSource(ints = { 318, 499, 533 }) + void webApplicationExceptionWithUnassignedHttpStatusCodeShouldNotFail(int status) { + given() + .queryParam("status", status) + .get("/throw/jax-rs/web-application-exception") + .then() + .statusCode(status) + .body("title", equalToIgnoringCase("Unknown Code")) + .body("status", equalTo(status)) + .body("stacktrace", nullValue()); + } + @Test void webApplicationExceptionShouldReturnHeaders() { int status = 429; diff --git a/runtime/src/main/java/io/quarkiverse/resteasy/problem/jaxrs/WebApplicationExceptionMapper.java b/runtime/src/main/java/io/quarkiverse/resteasy/problem/jaxrs/WebApplicationExceptionMapper.java index 7c1ca61..b348faa 100644 --- a/runtime/src/main/java/io/quarkiverse/resteasy/problem/jaxrs/WebApplicationExceptionMapper.java +++ b/runtime/src/main/java/io/quarkiverse/resteasy/problem/jaxrs/WebApplicationExceptionMapper.java @@ -18,7 +18,7 @@ public final class WebApplicationExceptionMapper extends ExceptionMapperBase