Skip to content

Commit

Permalink
Merge pull request #24138 from geoand/rr-multi-npe
Browse files Browse the repository at this point in the history
Prevent NPE when a JAX-RS method returns a Multi and does not declare @produces
  • Loading branch information
geoand authored Mar 7, 2022
2 parents f8b96e9 + 2b6ae07 commit 56dc389
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 56dc389

Please sign in to comment.