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

Spring JIRA | Neil Brown | 4 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  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

    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