8224217: RecordingInfo should use textual representation of path
Reviewed-by: mgronlun
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java Thu Jun 06 21:19:07 2019 +0800
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java Thu Jun 06 15:22:12 2019 +0200
@@ -315,7 +315,7 @@
private void dumpMemoryToDestination(PlatformRecording recording) {
WriteableUserPath dest = recording.getDestination();
if (dest != null) {
- MetadataRepository.getInstance().setOutput(dest.getText());
+ MetadataRepository.getInstance().setOutput(dest.getRealPathText());
recording.clearDestination();
}
}
@@ -406,7 +406,7 @@
event.id = r.getId();
event.name = r.getName();
WriteableUserPath p = r.getDestination();
- event.destination = p == null ? null : p.getText();
+ event.destination = p == null ? null : p.getRealPathText();
Duration d = r.getDuration();
event.recordingDuration = d == null ? Long.MAX_VALUE : d.toMillis();
Duration age = r.getMaxAge();
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java Thu Jun 06 21:19:07 2019 +0800
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java Thu Jun 06 15:22:12 2019 +0200
@@ -132,7 +132,7 @@
options.add("duration=" + Utils.formatTimespan(duration, ""));
}
if (destination != null) {
- options.add("filename=" + destination.getText());
+ options.add("filename=" + destination.getRealPathText());
}
String optionText = options.toString();
if (optionText.length() != 0) {
@@ -165,7 +165,7 @@
if (dest != null) {
try {
dumpStopped(dest);
- Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId() + ") to " + dest.getText());
+ Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId() + ") to " + dest.getRealPathText());
notifyIfStateChanged(newState, oldState);
close(); // remove if copied out
} catch(IOException e) {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/WriteableUserPath.java Thu Jun 06 21:19:07 2019 +0800
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/WriteableUserPath.java Thu Jun 06 15:22:12 2019 +0200
@@ -50,7 +50,8 @@
private final AccessControlContext controlContext;
private final Path original;
private final Path real;
- private final String text;
+ private final String realPathText;
+ private final String originalText;
// Not to ensure security, but to help
// against programming errors
@@ -68,8 +69,9 @@
BufferedWriter fw = Files.newBufferedWriter(path);
fw.close();
this.original = path;
+ this.originalText = path.toString();
this.real = path.toRealPath();
- this.text = real.toString();
+ this.realPathText = real.toString();
}
/**
@@ -85,15 +87,25 @@
}
/**
- * Returns a string representation of the path.
+ * Returns a string representation of the real path.
*
* @return path as text
*/
- public String getText() {
- return text;
+ public String getRealPathText() {
+ return realPathText;
}
/**
+ * Returns a string representation of the original path.
+ *
+ * @return path as text
+ */
+ public String getOriginalText() {
+ return originalText;
+ }
+
+
+ /**
* Returns a potentially malicious path where the user may have implemented
* their own version of Path. This method should never be called in an
* unsafe context and the Path value should never be passed along to other
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/management/ManagementSupport.java Thu Jun 06 21:19:07 2019 +0800
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/management/ManagementSupport.java Thu Jun 06 15:22:12 2019 +0200
@@ -31,12 +31,16 @@
import java.util.List;
import jdk.jfr.EventType;
+import jdk.jfr.Recording;
import jdk.jfr.internal.JVMSupport;
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.MetadataRepository;
+import jdk.jfr.internal.PlatformRecording;
+import jdk.jfr.internal.PrivateAccess;
import jdk.jfr.internal.Utils;
+import jdk.jfr.internal.WriteableUserPath;
import jdk.jfr.internal.instrument.JDKEvents;
/**
@@ -86,4 +90,12 @@
public static void logError(String message) {
Logger.log(LogTag.JFR, LogLevel.ERROR, message);
}
+
+ // Get the textual representation when the destination was set, which
+ // requires access to jdk.jfr.internal.PlatformRecording
+ public static String getDestinationOriginalText(Recording recording) {
+ PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
+ WriteableUserPath wup = pr.getDestination();
+ return wup == null ? null : wup.getOriginalText();
+ }
}
--- a/src/jdk.management.jfr/share/classes/jdk/management/jfr/RecordingInfo.java Thu Jun 06 21:19:07 2019 +0800
+++ b/src/jdk.management.jfr/share/classes/jdk/management/jfr/RecordingInfo.java Thu Jun 06 15:22:12 2019 +0200
@@ -25,7 +25,6 @@
package jdk.management.jfr;
-import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.LinkedHashMap;
@@ -37,6 +36,7 @@
import jdk.jfr.Recording;
import jdk.jfr.RecordingState;
+import jdk.jfr.internal.management.ManagementSupport;
/**
* Management representation of a {@code Recording}.
@@ -80,8 +80,7 @@
startTime = s == null ? 0L : s.toEpochMilli();
Instant st = recording.getStopTime();
stopTime = st == null ? 0L : st.toEpochMilli();
- Path p = recording.getDestination();
- destination = p == null ? null : p.toString();
+ destination = ManagementSupport.getDestinationOriginalText(recording);
Duration duration = recording.getDuration();
durationInSeconds = duration == null ? 0 : duration.getSeconds();
settings = recording.getSettings();