8288724: Prevent NullPointerException in serviceability/tmtools/jstack/DaemonThreadTest.java if jstack process fails

Reviewed-by: kevinw, sspitsyn
This commit is contained in:
Jaikiran Pai 2022-06-21 07:12:32 +00:00
parent ad8914616b
commit 5e680d0594

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -80,7 +80,10 @@ public class DaemonThreadTest {
// Run jstack tool and collect the output
JstackTool jstackTool = new JstackTool(ProcessHandle.current().pid());
ToolResults results = jstackTool.measure();
int exitCode = results.getExitCode();
if (exitCode != 0) {
throw new RuntimeException("jstack tool failed with an exit code " + exitCode);
}
// Analyze the jstack output for the correct thread type
JStack jstack = new DefaultFormat().parse(results.getStdoutString());
ThreadStack ti = jstack.getThreadStack(thread.getName());