-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Fix NPE if no database url is given and no embedded database is available #10626
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| * @author Phillip Webb | ||
| * @author Dave Syer | ||
| * @author Stephane Nicoll | ||
| * @author Kristine Jetzke | ||
| * @see #get(ClassLoader) | ||
| */ | ||
| public enum EmbeddedDatabaseConnection { | ||
|
|
@@ -106,7 +107,7 @@ public String getUrl() { | |
| */ | ||
| public String getUrl(String databaseName) { | ||
| Assert.hasText(databaseName, "DatabaseName must not be null."); | ||
| return String.format(this.url, databaseName); | ||
| return this.url != null ? String.format(this.url, databaseName) : null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That wasn't the intention as raised on #8690 - The idea is to avoid a NPE by an abuse of Thoughts?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the result for the user would basically be the same. I would prefer to not add the null check here because one of the enum constants is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference is that you give a perfectly valid exception message for a use case that isn't. I don't know if you've picked up that issue or if you faced it yourself but the issue as described doesn't result from a legit use case. I think we should then treat it as such.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is a legit use case to define DataSourceProperties without a url - at least in the current implementation. Because then this fallback to the embedded database takes place (in my opinion it would be better to not have this magic at all but it’s there already so I don’t think it can/should be changed and is definitely not in scope of this issue.)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Or I do. Let me run that thing concretely, thanks for the feedback. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think adding a logging statement here is part of what is discussed in the issue you've referenced.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea here was to give more insight into what's happening in the case described in the issue. As far as I understood it is hard to find out why there is this error because of the "magic" happening with with embedded database (i.e. no url means: try to connect to an embedded database)
But the original issue was about something different anyway, I was trying to do the
So I can remove the logging statement if you want.