From 2b6ae07c59282f56f9e085dd79d35dbd771d9c3e Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 7 Mar 2022 11:41:22 +0200 Subject: [PATCH] Prevent NPE when a JAX-RS method returns a Multi and does not declare @Produces Originally reported at: https://stackoverflow.com/q/71368733/2504224 --- .../server/handlers/PublisherResponseHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java index 64dc218adb12a..6fc4b848efb9e 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java @@ -12,6 +12,7 @@ import javax.ws.rs.core.MediaType; import org.jboss.logging.Logger; import org.jboss.resteasy.reactive.common.util.RestMediaType; +import org.jboss.resteasy.reactive.common.util.ServerMediaType; import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; import org.jboss.resteasy.reactive.server.core.SseUtil; import org.jboss.resteasy.reactive.server.core.StreamingUtil; @@ -243,7 +244,12 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti // media type negotiation and fixed entity writer set up, perhaps it's better than // cancelling the normal route? // or make this SSE produce build-time - MediaType[] mediaTypes = requestContext.getTarget().getProduces().getSortedOriginalMediaTypes(); + ServerMediaType produces = requestContext.getTarget().getProduces(); + if (produces == null) { + throw new IllegalStateException( + "Negotiation or dynamic media type not supported yet for Multi: please use the @Produces annotation when returning a Multi"); + } + MediaType[] mediaTypes = produces.getSortedOriginalMediaTypes(); if (mediaTypes.length != 1) { throw new IllegalStateException( "Negotiation or dynamic media type not supported yet for Multi: please use a single @Produces annotation");