Skip to content

IllegalArgumentException parsing several Accept header variations [SPR-9693] #14327

@spring-projects-issues

Description

@spring-projects-issues

Dan Checkoway opened SPR-9693 and commented

Attached is a file containing several variations of Accept header values that cause Spring to break. There was a prior ticket open for this, which dealt with single-quoted "profile" URLs in Accept headers. That is apparently fixed in 3.2. But these other variations are still broken. The test cases attached are all actual Accept headers we have seen "in the wild" coming from mobile devices.

Here are some examples of the types of exceptions we're seeing:

java.lang.IllegalArgumentException: 'mediaType' must not be empty
        at org.springframework.util.Assert.hasLength(Assert.java:136)
        at org.springframework.http.MediaType.parseMediaType(MediaType.java:638)
        at org.springframework.http.MediaType.parseMediaTypes(MediaType.java:691)
        at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.getAcceptedMediaTypes(ProducesRequestCondition.java:214)
        at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.access$4(ProducesRequestCondition.java:211)
        at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition$ProduceMediaTypeExpression.matchMediaType(ProducesRequestCondition.java:283)
        at org.springframework.web.servlet.mvc.condition.AbstractMediaTypeExpression.match(AbstractMediaTypeExpression.java:63)
        at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.getMatchingCondition(ProducesRequestCondition.java:163)
        at org.springframework.web.servlet.mvc.method.RequestMappingInfo.getMatchingCondition(RequestMappingInfo.java:175)
        at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getMatchingMapping(RequestMappingInfoHandlerMapping.java:64)
        at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getMatchingMapping(RequestMappingInfoHandlerMapping.java:1)
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.addMatchingMappings(AbstractHandlerMethodMapping.java:284)
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:251)
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:216)
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:1)
        at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:288)
        at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1063)
        at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1048)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:886)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Or...

java.lang.IllegalArgumentException: ";q=0.5" does not contain '/'
        at org.springframework.http.MediaType.parseMediaType(MediaType.java:648)
        at org.springframework.http.MediaType.parseMediaTypes(MediaType.java:691)
        at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.getAcceptedMediaTypes(ProducesRequestCondition.java:214)
        at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.access$4(ProducesRequestCondition.java:211)
        at org.springframework.web.servlet.mvc.condition.ProducesRequestCondition$ProduceMediaTypeExpression.matchMediaType(ProducesRequestCondition.java:283)
...

Affects: 3.1.1

Attachments:

Issue Links:

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions