org.springframework.web.multipart.MultipartException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Given the following bean configuration: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="test" /> <mvc:annotation-driven/> </beans> {code} and the following controller: {code:java} package test; // ... @Controller public class TestController { @RequestMapping("/home") @ResponseBody public String home(@RequestParam String param) { return param; } {code} and using them in a Servlet 2.5 environment (e.g. Tomcat 6) will result in the following exception when a request is made to {{/home}}: {noformat} org.springframework.web.multipart.MultipartException: Current request is not a multipart request at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:188) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) ... {noformat} This only occurs when Spring chooses to use the {{RequestMappingHandlerAdapter}} (as opposed to the deprecated {{AnnotationMethodHandlerAdapter}}). The root cause of this seems to be in the (somewhat recent) {{MultipartResolutionDelegate}} class. Its {{servletPartClass}} field remains {{null}} in pre Servlet 3.0 environments, and some equality checks yield false positives due to that. For instance: {code:java} private static boolean isPartCollection(MethodParameter methodParam) { return (servletPartClass == getCollectionParameterType(methodParam)); } private static Class<?> getCollectionParameterType(MethodParameter methodParam) { Class<?> paramType = methodParam.getNestedParameterType(); if (Collection.class == paramType || List.class.isAssignableFrom(paramType)){ Class<?> valueType = GenericCollectionTypeResolver.getCollectionParameterType(methodParam); if (valueType != null) { return valueType; } } return null; } {code} {{getCollectionParameterType}} returns {{null}} for non-collection parameters, which makes {{isPartCollection}} return {{true}}. The {{isPartArray}} method is plagued by the same issue (and maybe other places are too).
    via by Dmitri Gabbasov,
  • Given the following bean configuration: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:component-scan base-package="test" /> <mvc:annotation-driven/> </beans> {code} and the following controller: {code:java} package test; // ... @Controller public class TestController { @RequestMapping("/home") @ResponseBody public String home(@RequestParam String param) { return param; } {code} and using them in a Servlet 2.5 environment (e.g. Tomcat 6) will result in the following exception when a request is made to {{/home}}: {noformat} org.springframework.web.multipart.MultipartException: Current request is not a multipart request at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:188) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) ... {noformat} This only occurs when Spring chooses to use the {{RequestMappingHandlerAdapter}} (as opposed to the deprecated {{AnnotationMethodHandlerAdapter}}). The root cause of this seems to be in the (somewhat recent) {{MultipartResolutionDelegate}} class. Its {{servletPartClass}} field remains {{null}} in pre Servlet 3.0 environments, and some equality checks yield false positives due to that. For instance: {code:java} private static boolean isPartCollection(MethodParameter methodParam) { return (servletPartClass == getCollectionParameterType(methodParam)); } private static Class<?> getCollectionParameterType(MethodParameter methodParam) { Class<?> paramType = methodParam.getNestedParameterType(); if (Collection.class == paramType || List.class.isAssignableFrom(paramType)){ Class<?> valueType = GenericCollectionTypeResolver.getCollectionParameterType(methodParam); if (valueType != null) { return valueType; } } return null; } {code} {{getCollectionParameterType}} returns {{null}} for non-collection parameters, which makes {{isPartCollection}} return {{true}}. The {{isPartArray}} method is plagued by the same issue (and maybe other places are too).
    via by Dmitri Gabbasov,
  • Multiple Multipart File in Spring MVC - Ajax
    via Stack Overflow by K.Sumith
    ,
    • org.springframework.web.multipart.MultipartException: Current request is not a multipart request at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:188)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,
    kjhdofjosvskjhdofjosvs
    1 times, last one,
    dafmandafman
    2 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    wendellpereirawendellpereira
    4 times, last one,
    28 more bugmates