Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullpointerException WebApplicationException when Response Headers not set #343

Closed
YassineALLAL opened this issue Jan 15, 2024 · 2 comments · Fixed by #348
Closed

NullpointerException WebApplicationException when Response Headers not set #343

YassineALLAL opened this issue Jan 15, 2024 · 2 comments · Fixed by #348
Labels
bug Something isn't working

Comments

@YassineALLAL
Copy link

YassineALLAL commented Jan 15, 2024

When mapping a WebApplicationException whose response returns null for getHeaders, an NPE is thrown and the original exception informaiton is lost.

To Reproduce

  • Quarkus version: 3.5.2
  • quarkus-resteasy-problem 3.1.0

Use a rest client that returns null headers instead of an empty map (in my case, keycloak admin client).

    @Path("reproduce")
    @GET
    public RealmRepresentation reproduce() {
        return KeycloakBuilder.builder()
                .serverUrl("http://keycloak.obsidian.com")
                .clientId("admin-cli")
                .realm("404")
                .username("user")
                .password("password")
                .build()
                .realm("404")
                .toRepresentation();
    }
{
    "details": "Error id 44fbd7fa-b5c8-4c5e-87bf-91492cbd4d12-4, java.lang.NullPointerException: Cannot invoke \"jakarta.ws.rs.core.MultivaluedMap.forEach(java.util.function.BiConsumer)\" because the return value of \"jakarta.ws.rs.core.Response.getHeaders()\" is null",
    "stack": "java.lang.NullPointerException: Cannot invoke \"jakarta.ws.rs.core.MultivaluedMap.forEach(java.util.function.BiConsumer)\" because the return value of \"jakarta.ws.rs.core.Response.getHeaders()\" is null\n\tat com.tietoevry.quarkus.resteasy.problem.jaxrs.WebApplicationExceptionMapper.toProblem(WebApplicationExceptionMapper.java:28)\n\tat com.tietoevry.quarkus.resteasy.problem.jaxrs.WebApplicationExceptionMapper.toProblem(WebApplicationExceptionMapper.java:13)\n\tat com.tietoevry.quarkus.resteasy.problem.ExceptionMapperBase.toResponse(ExceptionMapperBase.java:23)\n\tat org.jboss.resteasy.reactive.server.core.RuntimeExceptionMapper.mapException(RuntimeExceptionMapper.java:100)\n\tat org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext.mapExceptionIfPresent(ResteasyReactiveRequestContext.java:337)\n\tat org.jboss.resteasy.reactive.server.handlers.ExceptionHandler.handle(ExceptionHandler.java:15)\n\tat io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:150)\n\tat org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)\n\tat io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582)\n\tat org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)\n\tat org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)\n\tat org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)\n\tat org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)\n\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)\n\tat java.base/java.lang.Thread.run(Thread.java:840)"
}

Expected behavior
Null headers should be handled gracefully:

{
    "status": 404,
    "title": "Not Found",
    "detail": "Received: 'Server response is: 404' when invoking: Rest Client method: 'org.keycloak.admin.client.token.TokenService#grantToken'",
    "instance": "/reproduce"
}
@lwitkowski
Copy link
Collaborator

@YassineALLAL I've just released the fix for this as https://github.com/TietoEVRY/quarkus-resteasy-problem/releases/tag/v3.7.0 and https://github.com/TietoEVRY/quarkus-resteasy-problem/releases/tag/v3.9.0 (depending on which Quarkus version is used). Thanks for reporting this!

@lwitkowski lwitkowski added the bug Something isn't working label Mar 28, 2024
@YassineALLAL
Copy link
Author

@lwitkowski Brilliant 🎉 thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants