8224217: RecordingInfo should use textual representation of path

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2019-06-06 15:22:12 +02:00
parent f4dfa02438
commit 77b1472e9b
5 changed files with 35 additions and 12 deletions

View File

@ -315,7 +315,7 @@ public final class PlatformRecorder {
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 @@ public final class PlatformRecorder {
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();

View File

@ -132,7 +132,7 @@ public final class PlatformRecording implements AutoCloseable {
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 @@ public final class PlatformRecording implements AutoCloseable {
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) {

View File

@ -50,7 +50,8 @@ public final class WriteableUserPath {
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 @@ public final class WriteableUserPath {
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,14 +87,24 @@ public final class WriteableUserPath {
}
/**
* 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

View File

@ -31,12 +31,16 @@ import java.util.Collections;
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 final class ManagementSupport {
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();
}
}

View File

@ -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 javax.management.openmbean.TabularData;
import jdk.jfr.Recording;
import jdk.jfr.RecordingState;
import jdk.jfr.internal.management.ManagementSupport;
/**
* Management representation of a {@code Recording}.
@ -80,8 +80,7 @@ public final class RecordingInfo {
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();