-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Ignore null HttpMessageConverter in RestTemplate and HttpMessageConverterExtractor #23140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If a null message converter is passed, restTemplate.postForObject will throw a NullPointerException. Checks are done to ensure it does not. Solves spring-projects#23123 Signed-off-by: RustyTheClone <[email protected]>
This is an edit from pull request: #23132 |
Tentatively slated for 5.2 RC1 and considering whether to backport to 5.1.x. |
@rstoyanchev and @jhoeller, shall we consider this a bug instead of an enhancement and assign it to |
Having |
@sbrannen I don't consider it a bug. It's simply a missing validation. |
Thanks for the feedback. I actually came to the same conclusion myself.
I agree that it is a user error if a
The challenge is that
Thus, users can modify the list (e.g., by appending/inserting I would rather perform the non-null validation every time the converters are accessed in @rstoyanchev, what do you think about that? |
I would definitely add checks in the constructor and setter since that would provide the benefit of an early warning. Beyond that I think it's not worth repeatedly checking for something that should not be happening in the first place. At that point it almost doesn't matter how it fails, NPE or IAE. Either way it fails it needs to be fixed in the application. |
Superseded by #23151 |
Prior to this commit, if a
null
HttpMessageConverter
was configuredin the
RestTemplate
, this would lead to aNullPointerException
oncethe list of converters was accessed.
This commit avoids such exceptions by ignoring
null
converters.See gh-23123