Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/iceberg/BaseTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.iceberg.io.LocationProvider;
import org.apache.iceberg.metrics.LoggingMetricsReporter;
import org.apache.iceberg.metrics.MetricsReporter;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;

/**
* Base {@link Table} implementation.
Expand All @@ -48,6 +49,7 @@ public BaseTable(TableOperations ops, String name) {
}

public BaseTable(TableOperations ops, String name, MetricsReporter reporter) {
Preconditions.checkNotNull(reporter, "reporter cannot be null");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Preconditions.checkNotNull(reporter, "reporter cannot be null");
Preconditions.checkArgument(null != reporter, Invalid metrics reporter: null");

Copy link
Member Author

Choose a reason for hiding this comment

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

it seems the codebase is generally OK using checkNotNull for null checks

$ git grep 'Preconditions.checkNotNull' | wc -l
392

are you saying this is passé?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we should prefer Preconditions.checkArgument here, because it indicates that a wrong argument has been passed and is therefore more expressive. Also we generally use Preconditions.checkArgument more than Preconditions.checkNotNull:

git grep 'Preconditions.checkArgument' | wc -l                                                                                                                                                                                                
1542

Copy link
Member Author

Choose a reason for hiding this comment

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

Also we generally use Preconditions.checkArgument more than Preconditions.checkNotNull:

do we use it commonly to check for nullness?

i think in the code i've contributed so far to iceberg i used cNN and don't remember being turned around to use cA

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah as Piotr suggested, it seems like there are multiple places we already use cNN for this, so I am fine with continuing to use that. @nastra what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

the reason why I made the suggestion is mainly because the error msg should be updated to Invalid metrics reporter: null. Additionally I checked the code around table scans and scan metrics. Since those places all use Preconditions.checkArgument it seems more appropriate to use the same here IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for @nastra's comment about the error message.

Whether we use checkNotNull or checkArgument doesn't really matter because both are ArgumentException. The problem with this is that it makes an unnecessary change to have an error message that doesn't fit with the conventions used elsewhere.

this.ops = ops;
this.name = name;
this.reporter = reporter;
Expand Down