java.lang.IllegalArgumentException: ";q=0.5" does not contain '/'

Spring JIRA | Dan Checkoway | 4 years ago
  1. 0

    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: {noformat} 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) {noformat} Or... {noformat} 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) ... {noformat}

    Spring JIRA | 4 years ago | Dan Checkoway
    java.lang.IllegalArgumentException: ";q=0.5" does not contain '/'
  2. 0

    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: {noformat} 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) {noformat} Or... {noformat} 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) ... {noformat}

    Spring JIRA | 4 years ago | Dan Checkoway
    java.lang.IllegalArgumentException: ";q=0.5" does not contain '/'
  3. 0

    what does this error messsage "Invalid token character ':' in token "Accept:text"" mean in spring mvc 3?

    Stack Overflow | 5 years ago | Bobo
    java.lang.IllegalArgumentException: Invalid token character ':' in token "Accept:text"
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    I have a REST service setup with the ContentNegotiatingViewResolver to transform responses into either xml or json based on the Accept header. I set the useNotAcceptableStatusCode property to true and it appears to work as expected. However, if the Accept header is a completely invalid media type like 'foo' then an exception is thrown and the consumer ends up getting back a 500 Internal Server Error instead of the expected 406. The top of the resulting stack trace is included below: SEVERE: Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception java.lang.IllegalArgumentException: "foo" does not contain '/' at org.springframework.http.MediaType.parseMediaType(MediaType.java:562) at org.springframework.http.MediaType.parseMediaTypes(MediaType.java:602) at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.getMediaTypes(ContentNegotiatingViewResolver.java:306) at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:366) at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1078) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1027) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.cerner.net.oauth.j2ee.filter.OAuthValidatorFilter$1.run(OAuthValidatorFilter.java:215) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:396) at com.cerner.net.oauth.j2ee.filter.OAuthValidatorFilter.doFilter(OAuthValidatorFilter.java:213) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) ... Considering that an invalid media type is a problem with the client making the request to the service, I think it should return a proper 406 response if the useNotAcceptableStatusCode flag is set.

    Spring JIRA | 6 years ago | Brett
    java.lang.IllegalArgumentException: "foo" does not contain '/'
  6. 0

    I have a REST service setup with the ContentNegotiatingViewResolver to transform responses into either xml or json based on the Accept header. I set the useNotAcceptableStatusCode property to true and it appears to work as expected. However, if the Accept header is a completely invalid media type like 'foo' then an exception is thrown and the consumer ends up getting back a 500 Internal Server Error instead of the expected 406. The top of the resulting stack trace is included below: SEVERE: Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception java.lang.IllegalArgumentException: "foo" does not contain '/' at org.springframework.http.MediaType.parseMediaType(MediaType.java:562) at org.springframework.http.MediaType.parseMediaTypes(MediaType.java:602) at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.getMediaTypes(ContentNegotiatingViewResolver.java:306) at org.springframework.web.servlet.view.ContentNegotiatingViewResolver.resolveViewName(ContentNegotiatingViewResolver.java:366) at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1078) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1027) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.cerner.net.oauth.j2ee.filter.OAuthValidatorFilter$1.run(OAuthValidatorFilter.java:215) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:396) at com.cerner.net.oauth.j2ee.filter.OAuthValidatorFilter.doFilter(OAuthValidatorFilter.java:213) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) ... Considering that an invalid media type is a problem with the client making the request to the service, I think it should return a proper 406 response if the useNotAcceptableStatusCode flag is set.

    Spring JIRA | 6 years ago | Brett
    java.lang.IllegalArgumentException: "foo" does not contain '/'

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      ";q=0.5" does not contain '/'

      at org.springframework.http.MediaType.parseMediaType()
    2. Spring
      MediaType.parseMediaTypes
      1. org.springframework.http.MediaType.parseMediaType(MediaType.java:648)
      2. org.springframework.http.MediaType.parseMediaTypes(MediaType.java:691)
      2 frames
    3. Spring MVC
      ProducesRequestCondition$ProduceMediaTypeExpression.matchMediaType
      1. org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.getAcceptedMediaTypes(ProducesRequestCondition.java:214)
      2. org.springframework.web.servlet.mvc.condition.ProducesRequestCondition.access$4(ProducesRequestCondition.java:211)
      3. org.springframework.web.servlet.mvc.condition.ProducesRequestCondition$ProduceMediaTypeExpression.matchMediaType(ProducesRequestCondition.java:283)
      3 frames