Skip to content

Commit

Permalink
Fix NullPointerException that would occur when WebApplicationExceptio…
Browse files Browse the repository at this point in the history
…n was thrown with an unassigned Http Status Code (#443)

Co-authored-by: JacobOJ <github.com/JacobOJ>
  • Loading branch information
JacobOJ authored Nov 19, 2024
1 parent c521113 commit 5dc7151
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class WebApplicationExceptionMapper extends ExceptionMapperBase<Web

@Override
protected HttpProblem toProblem(WebApplicationException exception) {
Response.StatusType status = Response.Status.fromStatusCode(exception.getResponse().getStatus());
Response.StatusType status = exception.getResponse().getStatusInfo();

HttpProblem.Builder problem = HttpProblem.builder()
.withTitle(status.getReasonPhrase())
Expand All @@ -32,5 +32,4 @@ protected HttpProblem toProblem(WebApplicationException exception) {

return problem.build();
}

}

0 comments on commit 5dc7151

Please sign in to comment.