Make it explicit that metrics reporter is required#6474
Conversation
| } | ||
|
|
||
| public BaseTable(TableOperations ops, String name, MetricsReporter reporter) { | ||
| Preconditions.checkNotNull(reporter, "reporter cannot be null"); |
There was a problem hiding this comment.
| Preconditions.checkNotNull(reporter, "reporter cannot be null"); | |
| Preconditions.checkArgument(null != reporter, Invalid metrics reporter: null"); |
There was a problem hiding this comment.
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é?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Also we generally use
Preconditions.checkArgumentmore thanPreconditions.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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
+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.
jackye1995
left a comment
There was a problem hiding this comment.
looks good to me, would be good if we reach some consensus about the way for null check, and change that to be consistent across codebase and add corresponding checkstyle rules.
thanks for your review @jackye1995 !
i prefer BTW, I am the library's user more frequently than its contributor. As a user, I would benefit from explicit indication which API methods accept nulls, and even more -- which can return nulls. This too, I would prefer to be a follow up, not a prerequisite for a merge here. |
I agree that it would improve things when it's more obvious that certain things can/cannot be null, e.g. through Re: cNN vs cA I think it's fine to go ahead and get this merged with what you prefer (assuming the error message is updated as mentioned above) as we don't want to block things from getting in while this is discussed. |
Yes this is the consequence of different styles of the projects. I like Trino's approach of checking null at every constructor and also use Optional as much as possible. For Iceberg, it would be ideal if nullability is at least indicated in documentation. |
|
I will merge this PR as suggested, and will create a Github issue for further discussion. |
That's a good point.
I like it too. That's why I fully supported @kokosing's push for to leverage Optional whenever possible.
100% agreed, especially if you mean API-level documentation (javadoc, annotations), as that's what library users will see in their IDEs. |
|
thanks for the merge! |
No description provided.