Skip to content
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

WIP: Use checker framework to check for nulls #373

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davecramer
Copy link
Contributor

We want to make sure we haven't introduced any subtle bugs by passing nulls where we shouldn't be.
Also reduce the number of places we are checking for nulls

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@davecramer davecramer requested a review from sergiyvamz March 27, 2023 15:16
@davecramer davecramer marked this pull request as draft March 27, 2023 15:16
@@ -33,6 +33,7 @@ public AwsWrapperProperty(
this(name, defaultValue, description, required, (String[]) null);
}

@SuppressWarnings({"nullness:argument","nullness:assignment"})
public AwsWrapperProperty(
String name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it makes sense to make it @nonnull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of places where the default value is null.
We would have to change the code to be compliant.

final String methodName,
final JdbcCallable<T, E> jdbcMethodFunc,
final Object[] jdbcMethodArgs)
final @Nullable Class<T> resultClass,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that @nonnull makes more sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I'm fairly certain we call it somewhere with a null

@@ -222,10 +232,10 @@ public void init(
this.plugins.add(defaultPlugin);
}

protected <T, E extends Exception> T executeWithSubscribedPlugins(
protected @Nullable <T, E extends Exception> T executeWithSubscribedPlugins(
final String methodName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -26,7 +27,7 @@
* An object representing connection info for a given host. Modifiable fields are thread-safe to support sharing this
* object with the EFM monitor thread.
*/
public class HostSpec {
public final class HostSpec {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would mind to explain why this class is final? Usually final classes are used in sensitive context like identity, user permissions, etc where altering class behaviour (by inheriting a new class) may create a vulnerability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you don't declare this final than a class that extends this can create a constructor that does not initialize all the fields

@@ -100,7 +103,7 @@ public static void setPropertyOnTarget(
() ->
Messages.get(
"PropertyUtils.failedToSetPropertyWithReason",
new Object[] {propName, target.getClass(), ex.getCause().getMessage()}));
new Object[] {propName, target.getClass() == null ? Messages.emptyArgs : target.getClass(), ex.getCause() == null ? Messages.emptyArgs : ex.getCause().getMessage()}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target == null || target.getClass() == null ?

Copy link
Contributor Author

@davecramer davecramer Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants