Skip to content

Conversation

@brettKK
Copy link

@brettKK brettKK commented Apr 30, 2018

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:

  return retFiles;
} catch (Exception e) {
  LOG.error("fail to parse zkSnapshot: " + lastZkSnapshot, e);
}

return null;

So parseZkSnapshot will return null while IOException happens. but its caller ZkGrep#processCommandLineArgs have no null checker:

File[] lastZkSnapshot = parseZkSnapshot(zkDataDirs[1], byTime);

// lastZkSnapshot[1] is the parsed last snapshot by byTime
grepZkSnapshot(lastZkSnapshot[1], patterns);

We should terminate the process while lastZkSnapshot == null

return outputFile;
} catch (IOException e) {
LOG.error("fail to gunzip file: " + zipFile, e);
throw new Exception("fail to gunzip file" + zipFile);

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 ?

Copy link
Contributor

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.

Copy link

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);
}

@brettKK

Copy link
Contributor

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.

Copy link

@lujiefsi lujiefsi left a 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]);
Copy link

Choose a reason for hiding this comment

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

hum, 0--->o???

Copy link
Contributor

@zhan849 zhan849 left a 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
@brettKK
Copy link
Author

brettKK commented May 5, 2018

@zhan849 thanks for your suggestion and I squash my commits into one commit.

@lujiefsi
Copy link

we should combine https://issues.apache.org/jira/browse/HELIX-701 with this pull request,

@brettKK
Copy link
Author

brettKK commented May 11, 2018

@lujiefsi , https://issues.apache.org/jira/browse/HELIX-701 has been automatically associated with this PR.

@asfgit asfgit force-pushed the master branch 2 times, most recently from 5ebe967 to 9d89e93 Compare November 16, 2018 23:57
@junkaixue junkaixue closed this Jul 22, 2019
@narendly narendly mentioned this pull request Dec 24, 2019
6 tasks
@huizhilu huizhilu mentioned this pull request Sep 1, 2020
4 tasks
@huizhilu huizhilu mentioned this pull request Sep 30, 2020
4 tasks
@kaisun2000 kaisun2000 mentioned this pull request Sep 30, 2020
4 tasks
@thestreak101 thestreak101 mentioned this pull request Jan 8, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants