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

Prevent NPE when a JAX-RS method returns a Multi and does not declare @Produces #24138

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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