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

fix: pass DCN_NULLPOINTER_EXCEPTION spotbugs error #8775

Merged
merged 1 commit into from
Feb 16, 2022

Conversation

swist
Copy link
Member

@swist swist commented Feb 16, 2022

Description

We have changed our SpotBugs version to 4.5.3 which was causing:

[ERROR] Medium: Do not catch NullPointerException like in io.confluent.ksql.datagen.DataGen$Arguments$Builder.build() [io.confluent.ksql.datagen.DataGen$Arguments$Builder] At DataGen.java:[line 440] DCN_NULLPOINTER_EXCEPTION
[INFO]

This change is SpotBugs compliant way of doing the same thing

  • explicit null checks, rather than delegating to a method
    that checks for null and throws NPE

Testing done

Verified that spotbugs is happy with the new code

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

We have changed our SpotBugs version to 4.5.3 which was causing:

```
[ERROR] Medium: Do not catch NullPointerException like in io.confluent.ksql.datagen.DataGen$Arguments$Builder.build() [io.confluent.ksql.datagen.DataGen$Arguments$Builder] At DataGen.java:[line 440] DCN_NULLPOINTER_EXCEPTION
[INFO]
```

This change is SpotBugs compliant way of doing the same thing
- explicit null checks, rather than delegating to a method
that checks for null and throws NPE
@swist swist requested a review from a team as a code owner February 16, 2022 12:55
Copy link
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

LGTM with a minor comment

Comment on lines +366 to +379
if (schemaFile == null) {
throw new ArgumentParseException("Schema file not provided");
}
if (keyFormat == null) {
throw new ArgumentParseException("Message key format not provided");
}
if (valueFormat == null) {
throw new ArgumentParseException("Message value format not provided");
}
if (topicName == null) {
throw new ArgumentParseException("Kafka topic name not provided");
}
if (keyName == null) {
throw new ArgumentParseException("Name of key column not provided");
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to deduplicate code by having a method like

void requireArgumentsNotNull(final Object argument, final String errorMessage) {
    if (argument == null) {
        throw new ArgumentParseException(errorMessage);
    }
}

But I am also fine with this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll land this and follow up separately

@swist swist requested review from cadonna and a team February 16, 2022 13:09
@swist swist merged commit afd7fb1 into confluentinc:master Feb 16, 2022
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