java.lang.IllegalArgumentException: "foo" does not contain '/'

Spring JIRA | Neil Brown | 4 years ago
  1. 0

    Having upgraded to 3.2.1 I've retested the fix to SPR-9534 (marked as a duplicate of, and resolved by SPR-9142). Whilst some cases of this issue have been fixed (thanks) there is still at least one scenario where the IllegalArgumentException thrown by MediaType.parseMediaType() is not being handled - when no handler is matched. For example, given the following Controller mapping - {code} @Controller @RequestMapping(value = "/channel/{channelId}/communication") public class CommunicationController { ... @RequestMapping(value = "/{commId}/registration", method = RequestMethod.POST, consumes = "application/xml") @ResponseStatus(value = HttpStatus.CREATED) public void preregister(@PathVariable Integer channelId, @PathVariable Integer commId, @RequestBody UserDto userDto, HttpServletRequest request) { ... } ... } {code} A Content-Type header of value "foo", results in an IllegalArgumentException, as per stack-trace: {code} java.lang.IllegalArgumentException: "foo" does not contain '/' at org.springframework.http.MediaType.parseMediaType(MediaType.java:697) at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:208) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:282) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:222) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:55) at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:297) at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1091) at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1076) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:896) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) .... {code} *Note* - It may also be useful to note that this problem also existed under 3.1.2 (i.e. it is NOT a SPR-9142 backport error/issue), but rather an edge-case that hasn't already been fixed.

    Spring JIRA | 4 years ago | Neil Brown
    java.lang.IllegalArgumentException: "foo" does not contain '/'
  2. 0

    Having upgraded to 3.2.1 I've retested the fix to SPR-9534 (marked as a duplicate of, and resolved by SPR-9142). Whilst some cases of this issue have been fixed (thanks) there is still at least one scenario where the IllegalArgumentException thrown by MediaType.parseMediaType() is not being handled - when no handler is matched. For example, given the following Controller mapping - {code} @Controller @RequestMapping(value = "/channel/{channelId}/communication") public class CommunicationController { ... @RequestMapping(value = "/{commId}/registration", method = RequestMethod.POST, consumes = "application/xml") @ResponseStatus(value = HttpStatus.CREATED) public void preregister(@PathVariable Integer channelId, @PathVariable Integer commId, @RequestBody UserDto userDto, HttpServletRequest request) { ... } ... } {code} A Content-Type header of value "foo", results in an IllegalArgumentException, as per stack-trace: {code} java.lang.IllegalArgumentException: "foo" does not contain '/' at org.springframework.http.MediaType.parseMediaType(MediaType.java:697) at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:208) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:282) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:222) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:55) at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:297) at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1091) at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1076) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:896) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) .... {code} *Note* - It may also be useful to note that this problem also existed under 3.1.2 (i.e. it is NOT a SPR-9142 backport error/issue), but rather an edge-case that hasn't already been fixed.

    Spring JIRA | 4 years ago | Neil Brown
    java.lang.IllegalArgumentException: "foo" does not contain '/'
  3. 0

    java.lang.IllegalArgumentException: "json" does not contain '/'

    Stack Overflow | 3 years ago | Pneumokok
    java.lang.IllegalArgumentException: "json" does not contain '/'
  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

      "foo" does not contain '/'

      at org.springframework.http.MediaType.parseMediaType()
    2. Spring
      MediaType.parseMediaType
      1. org.springframework.http.MediaType.parseMediaType(MediaType.java:697)
      1 frame
    3. Spring MVC
      FrameworkServlet.doPost
      1. org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:208)
      2. org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:282)
      3. org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:222)
      4. org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:55)
      5. org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:297)
      6. org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1091)
      7. org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1076)
      8. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:896)
      9. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      10. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
      11. org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827)
      11 frames
    4. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      1 frame
    5. Spring MVC
      FrameworkServlet.service
      1. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)
      1 frame
    6. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      1 frame