MINOR: Catch null pointer exception for empty leader URL when assignment is null#4798
MINOR: Catch null pointer exception for empty leader URL when assignment is null#4798guozhangwang merged 1 commit intoapache:trunkfrom asdf2014:null_leader_url
Conversation
|
Hi, @guozhangwang . PTAL. |
kkonstantine
left a comment
There was a problem hiding this comment.
Thanks @asdf2014 for spotting this. I left a comment.
There was a problem hiding this comment.
I'd rather not use exception handling for branching. I think I'd prefer to address this case with an earlier check for leaderUrl() == null and instantiate a more informative exception to pass to cb.onCompletion
|
Hi, @kkonstantine @guozhangwang . Already using more informative exception instead of |
rhauch
left a comment
There was a problem hiding this comment.
One minor suggestion to make it even more readable.
There was a problem hiding this comment.
Maybe leaderUrl.trim().isEmpty() instead?
There was a problem hiding this comment.
Indeed, isEmpty() is better.
kkonstantine
left a comment
There was a problem hiding this comment.
I left a few minor comments to improve the exception message and the readability of the code.
Finally, an observation I have is that we now throw an exception which we know it should (and will) be caught right below. Another way to write this, would be to pass the exception to cb.onCompletion immediately. E.g.
Exception e = new ConnectException(...);
cb.onCompletion(e, null);
Since this is not expected to have an impact on the efficiency of the code here, this is more of a stylistic comment than anything else. Up to you @asdf2014
There was a problem hiding this comment.
nit: , (comma) doesn't seem required in the sentence.
There was a problem hiding this comment.
All right. I remove it :-)
There was a problem hiding this comment.
suggestion: because the URL of the leader's REST interface is empty
(otherwise it should have been due to the URL of the leader's REST interface being empty)
There was a problem hiding this comment.
Yep, you are right. It is better.
There was a problem hiding this comment.
Although the checkstyle rules currently do not enforce curly brackets in if/else blocks that contain a single statement, because this statement here spans multiple lines, I feel it'd be best to enclose it within { }, even if that's optional.
There was a problem hiding this comment.
Sure, i will follow the code style.
|
Thanks for your suggestions. Already fixed. @kkonstantine |
…signment is null * Using more informative exception instead of `NullPointerException` * Using isEmpty instead of `lenght == 0` * Add brackets for if clause and improve the connect exception message
|
Hi, @rhauch @kkonstantine . This PR has been squashed and rebased. PTAL. |
…signment is null (apache#4798) Catch null pointer exception for empty leader URL when assignment is null. Reviewers: Randall Hauch <rhauch@gmail.com>, Konstantine Karantasis <konstantine@confluent.io>, Guozhang Wang <wangguoz@gmail.com>
Catch null pointer exception for empty leader URL when assignment is null.
Committer Checklist (excluded from commit message)