-
-
Notifications
You must be signed in to change notification settings - Fork 101
Ensure config is present and not null #592
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
|
In my opinion we should modify some of our code to support disabling some functionalities, I don't know what you think about this? This doesn't have to be super complicated, just somekind of a validation method, and if it fails none of the classes/commands are registered to begin with. |
application/src/main/java/org/togetherjava/tjbot/config/SuggestionsConfig.java
Show resolved
Hide resolved
|
@Tais993 Yes, would be a good addition. Right now, the gist feature just throws exceptions and the log-forwarded PR by me simply disables the feature if the webhook in the config throws an exception bc its not an URL. So my log forwarded explicitly supports this situation, but not in a nice way. |
1930d24 to
433e195
Compare
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.
The singular issue I have with this, is that it just gives an unclear error.
Objects.requireNonNull(token, "The token from the config cannot be null");While my phrasing is bad here, at least it instantly gets to the point, otherwise it'd still be a little vague and you have to check more than just the error message.
If that's modified, I'm fine with it, but i dont like it how it is rn
application/src/main/java/org/togetherjava/tjbot/config/Config.java
Outdated
Show resolved
Hide resolved
The problem I have with the "proper fix" is that it bloats it even further. On the good side:
And the stacktrace ofc at least links the exact line that had an issue. But yeah, maybe Ill just add it... |
|
I understand the bloat concern very much, I'll accept this PR. The |
433e195 to
470e995
Compare
|
Kudos, SonarCloud Quality Gate passed! |








Overview
Our code incorrectly allowed missing config properties. Such as just leaving out an entry, for example
gistApiKey. Or even explicitly setting it tonull:both lead to Jackson constructing our
Configwithnullfor this field.This is a problem, because our code implicitly assumes
@Nonnullon all these fields and getter methods, in the whole code base. And we obviously also never accounted for this situation in our code, nor do we want to.Fix
This approaches the problem by correctly documenting and enforcing that all properties of configs are required. The code now throws for both those situations:
This is achieved by two mechanisms:
this.foo = Objects.requireNonNull(foo)for explicit nulls like"foo" = null,@JsonProperty(value = "foo", required = true)for leaving it out alltogetherUnfortunately, this makes the already ugly config files even uglier. Doesnt seem like there is a better or more automatic way of applying this everywhere in the config.