8230767: FlightRecorderListener returns null recording

Reviewed-by: mseledtsov, mgronlun
This commit is contained in:
Erik Gahlin 2019-11-11 14:47:37 +01:00
parent 43368f8f9f
commit b3d2b3ba5f
2 changed files with 41 additions and 1 deletions

View File

@ -484,7 +484,10 @@ public final class PlatformRecording implements AutoCloseable {
}
for (FlightRecorderListener cl : PlatformRecorder.getListeners()) {
try {
cl.recordingStateChanged(getRecording());
// Skip internal recordings
if (recording != null) {
cl.recordingStateChanged(recording);
}
} catch (RuntimeException re) {
Logger.log(JFR, WARN, "Error notifying recorder listener:" + re.getMessage());
}

View File

@ -0,0 +1,37 @@
package jdk.jfr.api.recorder;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicBoolean;
import jdk.jfr.FlightRecorder;
import jdk.jfr.FlightRecorderListener;
import jdk.jfr.Recording;
/**
* @test TestRecorderListenerWithDump
*
* @key jfr
* @requires vm.hasJFR
* @run main/othervm jdk.jfr.api.recorder.TestRecorderListenerWithDump
*/
public class TestRecorderListenerWithDump {
public static void main(String... args) throws Exception {
AtomicBoolean nullRecording = new AtomicBoolean();
FlightRecorder.addListener(new FlightRecorderListener() {
public void recordingStateChanged(Recording r) {
if (r == null) {
nullRecording.set(true);
} else {
System.out.println("Recording " + r.getName() + " " + r.getState());
}
}
});
try (Recording r = new Recording()) {
r.start();
r.dump(Paths.get("dump.jfr"));
}
if (nullRecording.get()) {
throw new Exception("FlightRecorderListener returned null recording");
}
}
}