Affects: \ 5.1.5


The default file upload uses StandardServletMultipartResolver. When the file upload exceeds the size, why the maxUploadSize of MaxUploadSizeExceededException is always -1, but the exception can be captured in CommonsMultipartResolver and the file size can be correctly assigned

Cause the problem, using StandardServletMultipartResolver, the external can not catch the exception correctly to get the file size exceeding

StandardMultipartHttpServletRequest
protected void handleParseFailure(Throwable ex) {
        String msg = ex.getMessage();
        if (msg != null && msg.contains("size") && msg.contains("exceed")) {
            throw new MaxUploadSizeExceededException(-1, ex);
        }
        throw new MultipartException("Failed to parse multipart servlet request", ex);
    }

CommonsMultipartResolver
  protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
        String encoding = this.determineEncoding(request);
        FileUpload fileUpload = this.prepareFileUpload(encoding);

        try {
            List<FileItem> fileItems = ((ServletFileUpload)fileUpload).parseRequest(request);
            return this.parseFileItems(fileItems, encoding);
        } catch (SizeLimitExceededException var5) {
            throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), var5);
        } catch (FileSizeLimitExceededException var6) {
            throw new MaxUploadSizeExceededException(fileUpload.getFileSizeMax(), var6);
        } catch (FileUploadException var7) {
            throw new MultipartException("Failed to parse multipart servlet request", var7);
        }
    }

Comment From: rstoyanchev

That's something configured via ServletRegistration.Dynamic or in web.xml on startup but cannot be accessed at runtime, so it is simply not available. Does the exception from the underlying container not have the max size? I can't see any reason why it shouldn't since the container actually has the knowledge. In any case nothing I can see that we can do.

Comment From: tofdragon

https://github.com/spring-projects/spring-framework/issues/13932