HeaderContentNegotiationStrategy.resolveMediaTypes()
throws unexpected InvalidMimeTypeException
#32483
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Overview
In #31769 (comment), @jandroalvarez brought it to our attention that the fix for #31254 resulted in an
InvalidMimeTypeException
being thrown byMimeTypeUtils.sortBySpecificity()
instead of anIllegalArgumentException
.However,
InvalidMimeTypeException
extendsIllegalArgumentException
.Consequently, the change from
IllegalArgumentException
toInvalidMimeTypeException
did not result in the desired effect inHeaderContentNegotiationStrategy.resolveMediaTypes
.HeaderContentNegotiationStrategy.resolveMediaTypes()
still allows theInvalidMimeTypeException
to propagate as-is without wrapping it in anHttpMediaTypeNotAcceptableException
.We should therefore catch both
InvalidMediaTypeException
andInvalidMimeTypeException
inHeaderContentNegotiationStrategy.resolveMediaTypes()
and wrap the exception in anHttpMediaTypeNotAcceptableException
.Proposed Fix and Test
catch (InvalidMediaTypeException | InvalidMimeTypeException ex)
inHeaderContentNegotiationStrategy.resolveMediaTypes()
.The text was updated successfully, but these errors were encountered: