Skip to content

Commit 899b92b

Browse files
committed
[GR-63621] ProfilerCLI incorrectly handles Source#getPath.
PullRequest: graal/20432
2 parents 6a550f9 + 9e33d01 commit 899b92b

File tree

1 file changed

+17
-7
lines changed
  • tools/src/com.oracle.truffle.tools.profiler/src/com/oracle/truffle/tools/profiler/impl

1 file changed

+17
-7
lines changed

tools/src/com.oracle.truffle.tools.profiler/src/com/oracle/truffle/tools/profiler/impl/ProfilerCLI.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
package com.oracle.truffle.tools.profiler.impl;
2626

2727
import java.io.File;
28+
import java.net.URL;
2829
import java.nio.file.Path;
29-
import java.nio.file.Paths;
3030
import java.util.ArrayList;
3131
import java.util.List;
3232
import java.util.Objects;
@@ -106,17 +106,27 @@ static String getShortDescription(SourceSection sourceSection) {
106106
return UNKNOWN;
107107
}
108108
StringBuilder b = new StringBuilder();
109-
if (sourceSection.getSource().getPath() == null) {
110-
b.append(sourceSection.getSource().getName());
111-
} else {
112-
Path pathAbsolute = Paths.get(sourceSection.getSource().getPath());
113-
Path pathBase = new File("").getAbsoluteFile().toPath();
109+
Source source = sourceSection.getSource();
110+
URL url = source.getURL();
111+
if (url != null && !"file".equals(url.getProtocol())) {
112+
b.append(url.toExternalForm());
113+
} else if (source.getPath() != null) {
114114
try {
115+
/*
116+
* On Windows, getPath for a local file URL returns a path in the format
117+
* `/C:/Documents/`, which is not a valid file system path on Windows. Attempting to
118+
* parse this path using Path#of results in a failure. However, java.io.File
119+
* correctly handles this format by removing the invalid leading `/` character.
120+
*/
121+
Path pathAbsolute = new File(source.getPath()).toPath();
122+
Path pathBase = new File("").getAbsoluteFile().toPath();
115123
Path pathRelative = pathBase.relativize(pathAbsolute);
116124
b.append(pathRelative.toFile());
117125
} catch (IllegalArgumentException e) {
118-
b.append(sourceSection.getSource().getName());
126+
b.append(source.getName());
119127
}
128+
} else {
129+
b.append(source.getName());
120130
}
121131

122132
b.append("~").append(formatIndices(sourceSection, true));

0 commit comments

Comments
 (0)