throw new Exception to avoid ugly NPE#200
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.
The Exception message should contains the original IOException ?
There was a problem hiding this comment.
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.
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.
@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.
| // 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]); |
zhan849
left a comment
There was a problem hiding this comment.
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