The code that determines whether to run handleEmptyBody depends on other factors besides the body not being provided. I have attached a simple application that shows the issue (test.zip). The application is comprised of 1 controller and 1 advice.
If the endpoint is called without a body and no content type, the advice will not run (note that the endpoint returns 200):
curl -X POST http://localhost:8080/identity
If the endpoint is called without a body but with a content type, the advice will run (note that the endpoint returns 200):
curl -X POST http://localhost:8080/identity -H 'Content-Type: application/json'
If we inspect AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters()
we see that in the first case the content type is set to application/octet-stream
while in the second it is set to application/json
. The converter is not able to handle application/octet-stream
so the if
and handleEmptyBody
will not run. Sending the content type header is unnecessary when there is no body, so the behaviour of running handleEmptyBody
shouldn't depend on it.