This is for the new MultipartHttpMessageConverter for 7.1 added recently in #33263.
There are 3 levels of handling where exceptions can occur:
Multiparser (parse) -> Multiparser.State (data|complete) -> PartListener (onHeader|onBody)
At the lowest level, the only PartListener implementation (PartGenerator) handles any exception arising from the handling of body data, cleans up resources, and throws HttpMessageConversionException.
The middle layer Multiparser.State implementations can throw HttpMessageConversionException (e.g. header size exceeded), in which case they also delegate to PartListener#onError to clean up, but don't consistently clean up their own state. There is also an implicit reliance on PartListener to handle all exceptions, which is not made explicit.
At the top, Multiparser handles only InputStream read IOException by calling State#dispose and PartListener#onError to clean up resources. If the lower layers raise HttpMessageConversionException, it means that's been handled, but any other unexpected exception is not.
We can make the expectations and responsibilities clear across the layers, and also tighten handling.
This is for the new
MultipartHttpMessageConverterfor 7.1 added recently in #33263.There are 3 levels of handling where exceptions can occur:
Multiparser (parse) -> Multiparser.State (data|complete) -> PartListener (onHeader|onBody)
At the lowest level, the only
PartListenerimplementation (PartGenerator) handles any exception arising from the handling of body data, cleans up resources, and throwsHttpMessageConversionException.The middle layer
Multiparser.Stateimplementations can throwHttpMessageConversionException(e.g. header size exceeded), in which case they also delegate toPartListener#onErrorto clean up, but don't consistently clean up their own state. There is also an implicit reliance onPartListenerto handle all exceptions, which is not made explicit.At the top,
Multiparserhandles only InputStream readIOExceptionby callingState#disposeandPartListener#onErrorto clean up resources. If the lower layers raiseHttpMessageConversionException, it means that's been handled, but any other unexpected exception is not.We can make the expectations and responsibilities clear across the layers, and also tighten handling.