Skip to content

Conversation

Zabuzard
Copy link
Member

Overview

Our code incorrectly allowed missing config properties. Such as just leaving out an entry, for example gistApiKey. Or even explicitly setting it to null:

"gistApiKey": null,

both lead to Jackson constructing our Config with null for this field.

This is a problem, because our code implicitly assumes @Nonnull on 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:

exception

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 alltogether

Unfortunately, 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.

@Zabuzard Zabuzard added bug Something isn't working priority: low labels Sep 30, 2022
@Zabuzard Zabuzard self-assigned this Sep 30, 2022
@Zabuzard Zabuzard requested review from a team as code owners September 30, 2022 12:21
@Tais993
Copy link
Member

Tais993 commented Sep 30, 2022

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.

@Zabuzard
Copy link
Member Author

@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.

@Zabuzard Zabuzard force-pushed the feature/config_non_null branch from 1930d24 to 433e195 Compare September 30, 2022 13:06
Copy link
Member

@Tais993 Tais993 left a 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

@Zabuzard
Copy link
Member Author

Zabuzard commented Oct 4, 2022

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

The problem I have with the "proper fix" is that it bloats it even further.

On the good side:

  • this check only triggers when you explicitly set something to null. In practice, that is unlikely. When you just leave it out, the required = true from Jackson will give you a direct and helpful error message.

And the stacktrace ofc at least links the exact line that had an issue.

But yeah, maybe Ill just add it...

@Tais993
Copy link
Member

Tais993 commented Oct 4, 2022

I understand the bloat concern very much, I'll accept this PR. The required = true already fixes 99% of the cases

@Zabuzard Zabuzard force-pushed the feature/config_non_null branch from 433e195 to 470e995 Compare October 4, 2022 08:37
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Zabuzard Zabuzard merged commit 6d9f6c0 into develop Oct 4, 2022
@Zabuzard Zabuzard deleted the feature/config_non_null branch October 4, 2022 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants