Add a null check to method TestUtils.compressHeapDumps (#10053)

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.
This commit is contained in:
feijermu 2020-02-25 16:37:52 +08:00 committed by Norman Maurer
parent 639f5c9d48
commit 447a3f2d83

View File

@ -135,6 +135,10 @@ public final class TestUtils {
public static void compressHeapDumps() throws IOException {
final File[] files = new File(System.getProperty("user.dir")).listFiles((dir, name) -> 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);