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:
parent
639f5c9d48
commit
447a3f2d83
@ -135,6 +135,10 @@ public final class TestUtils {
|
|||||||
|
|
||||||
public static void compressHeapDumps() throws IOException {
|
public static void compressHeapDumps() throws IOException {
|
||||||
final File[] files = new File(System.getProperty("user.dir")).listFiles((dir, name) -> name.endsWith(".hprof"));
|
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 byte[] buf = new byte[65536];
|
||||||
final LZMA2Options options = new LZMA2Options(LZMA2Options.PRESET_DEFAULT);
|
final LZMA2Options options = new LZMA2Options(LZMA2Options.PRESET_DEFAULT);
|
||||||
|
Loading…
Reference in New Issue
Block a user