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 GitHub
parent 880e1239c5
commit 6d09298d1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -141,6 +141,10 @@ public final class TestUtils {
return name.endsWith(".hprof"); 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 byte[] buf = new byte[65536];
final LZMA2Options options = new LZMA2Options(LZMA2Options.PRESET_DEFAULT); final LZMA2Options options = new LZMA2Options(LZMA2Options.PRESET_DEFAULT);