# HG changeset patch # User egahlin # Date 1573480057 -3600 # Node ID d4cae08239f7bd2bbfbc4889afead97d0661ee53 # Parent 0c5fb962e11e46f8aafca0cc2829421cf89f4301 8230767: FlightRecorderListener returns null recording Reviewed-by: mseledtsov, mgronlun diff -r 0c5fb962e11e -r d4cae08239f7 src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java Mon Nov 11 05:09:31 2019 -0800 +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java Mon Nov 11 14:47:37 2019 +0100 @@ -484,7 +484,10 @@ } 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()); } diff -r 0c5fb962e11e -r d4cae08239f7 test/jdk/jdk/jfr/api/recorder/TestRecorderListenerWithDump.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/jdk/jfr/api/recorder/TestRecorderListenerWithDump.java Mon Nov 11 14:47:37 2019 +0100 @@ -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"); + } + } +}