Skip to content

Commit

Permalink
Add a null check to method TestUtils.compressHeapDumps (#10053)
Browse files Browse the repository at this point in the history
Motivation:

java.io.File.listFiles() may return null and cause a unexpected NPE.

Modification:

Add a null check for variable files. And if variable files is null, the compressHeapDumps method will just return after logging a error message.

Result:

Fix the potential NPE.
  • Loading branch information
seedeed committed Feb 25, 2020
1 parent 880e123 commit 6d09298
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public boolean accept(File dir, String name) {
return name.endsWith(".hprof");
}
});
if (files == null) {
logger.warn("failed to find heap dump due to I/O error!");
return;
}

final byte[] buf = new byte[65536];
final LZMA2Options options = new LZMA2Options(LZMA2Options.PRESET_DEFAULT);
Expand Down

0 comments on commit 6d09298

Please sign in to comment.