Hi Team:
Recently, we noticed that a large number of NumberFormatExceptions are
being generated when parsing
multipart parts, and that approximately 20% of the CPU time spent parsing
multipart requests is
consumed by generating these exceptions.
These exceptions originate from `FileItemIteratorImpl.findNextItem ->
getContentLength`, which attempts
to retrieve the content-length from each part.
```java
private long getContentLength(final FileItemHeaders pHeaders) {
try {
return
Long.parseLong(pHeaders.getHeader(FileUploadBase.CONTENT_LENGTH));
} catch (final Exception e) {
return -1;
}
}
```
However, according to https://www.rfc-editor.org/info/rfc7578/#section-4.8
, common multipart/form-data
requests do not include a Content-Length header, which means most
multipart/form-data requests will
generate a NumberFormatException.
--------------
The multipart/form-data media type does not support any MIME header
fields in parts other than Content-Type, Content-Disposition, and (in
limited circumstances) Content-Transfer-Encoding. Other header
fields MUST NOT be included and MUST be ignored.
--------------
So, do you think we should add a null check before calling parseLong to
avoid generating exceptions in
this common scenario?
Best Regards
Chunhui Liu
2026-11-24