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
NullPointerException in RoutingDataSourceHealthContributor when a routing data source has a target with a null routing key #27698
Conversation
The RoutingDataSourceHealthContributor constructor throws a NullPointerException (NPE) if the provided map has a null key. With this commit the NPE issue has been fixed by filtering the entries that are not-null. This closes spring-projects#27694
Updating the file author as per the commit message guide
Thanks for the pull-request @thegeekyasian. I'm wondering if we'd be better off changing We should also add some tests to Are you interested in updating your pull request in that direction? |
Thanks @philwebb Definitely, we can replace the null one with a public constant string value 'unnamed'. I would like to do the suggested changes and update the PR. Another option that we have is to keep null values with 'null' key with the below code snippet:
Thoughts? |
@thegeekyasian I don't think |
@philwebb Ah, I see! 'unnamed' key is the way to go then. Should a warning be logged in this case though, when setting the datasource for unnamed? |
From @timmalich in #27694 (comment)
Thank you both very much. Wouldn't that filter just drop an otherwise valid configuration? Wouldn't it be better to check null within the next line? Like: Option 2) Would it be possible to at least log a warning? |
I think the warning is unnecessary since the health info name is only for reference. The only problem might be if |
Instead of throwing an exception, the datasource will be saved as 'unnamed' in the map. In this commit, the 'unnamed' key has been added, along with the required tests
@philwebb, the PR has been updated with the suggested changes and the tests have been updated to assert the 'unnamed' datasource. With the change done, even if the |
@thegeekyasian Thanks very much for making your first contribution to Spring Boot. |
The RoutingDataSourceHealthContributor constructor throws a NullPointerException (NPE) if the provided map has a null key. With this commit the NPE issue has been fixed by filtering the entries that are not-null.
Alternatively, a constant value can be added when the key for a datasource in the ‘Map’ is null.
This closes #27694