-
Notifications
You must be signed in to change notification settings - Fork 242
throw new Exception to avoid ugly NPE #200
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
Conversation
| return outputFile; | ||
| } catch (IOException e) { | ||
| LOG.error("fail to gunzip file: " + zipFile, e); | ||
| throw new Exception("fail to gunzip file" + zipFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Exception message should contains the original IOException ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
Tooling is fine here as NPE is caught outside, and proper error message are printed out.
BTW, wrapping IOException using generic Exception will erase the proper semantics that IOException carries, which is not a good practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not we check the null in ZkGrep#processCommandLineArgs:
if (lastZkSnapshot == null){
LOG.error("fail to gunzip file" + zkDataDirs[1]);
System.exit(1);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lujiefsi might not be a good idea to only check lastZkSnapshot, because gunzip() is used in multiple places and you need to check all of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 LGTM. these changes avoid duplicate exception, and also have enough log message for post-mortem debug
| // zkDataDirs[0] is the transaction log dir | ||
| List<File> parsedZkLogs = parseZkLogs(zkDataDirs[0], startTime, endTime); | ||
| if (parsedZkLogs == null) { | ||
| LOG.error("fail t0 gunzip file" + zkDataDirs[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum, 0--->o???
zhan849
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok now it looks good to me. Can you pls squash your commits into 1 and I will contact with committers to help you merge
delete unreachable return statement' add SYstem.exit to instead of Exception recover code add null check fix spelling error
|
@zhan849 thanks for your suggestion and I squash my commits into one commit. |
|
we should combine https://issues.apache.org/jira/browse/HELIX-701 with this pull request, |
|
@lujiefsi , https://issues.apache.org/jira/browse/HELIX-701 has been automatically associated with this PR. |
5ebe967 to
9d89e93
Compare
We have developed a static analysis tool NPEDetector to find some potential NPE. Our analysis shows that some callees may return null in corner case(e.g. node crash , IOException), some of their callers have !=null check but some do not have. In this issue we post a patch which can add !=null based on existed !=null check. For example:
ZkGrep#parseZkSnapshot:
So parseZkSnapshot will return null while IOException happens. but its caller ZkGrep#processCommandLineArgs have no null checker:
We should terminate the process while lastZkSnapshot == null