Skip to content

Commit 764ad48

Browse files
committed
Fix Thread::Backtrace::Location#absolute_path to return an absolute path for a relative main script
(cherry picked from commit 3944ed5)
1 parent d276418 commit 764ad48

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/org/truffleruby/core/thread/ThreadBacktraceLocationNodes.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
package org.truffleruby.core.thread;
1111

12-
import java.io.File;
13-
1412
import org.jcodings.specific.UTF8Encoding;
1513
import org.truffleruby.Layouts;
1614
import org.truffleruby.RubyContext;
@@ -22,14 +20,15 @@
2220
import org.truffleruby.core.string.StringNodes;
2321
import org.truffleruby.core.string.StringOperations;
2422
import org.truffleruby.language.backtrace.Backtrace;
23+
import org.truffleruby.language.backtrace.BacktraceFormatter;
2524

2625
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2726
import com.oracle.truffle.api.TruffleStackTraceElement;
2827
import com.oracle.truffle.api.dsl.Cached;
2928
import com.oracle.truffle.api.dsl.Specialization;
3029
import com.oracle.truffle.api.object.DynamicObject;
30+
import com.oracle.truffle.api.source.Source;
3131
import com.oracle.truffle.api.source.SourceSection;
32-
import org.truffleruby.language.backtrace.BacktraceFormatter;
3332

3433
@CoreModule(value = "Thread::Backtrace::Location", isClass = true)
3534
public class ThreadBacktraceLocationNodes {
@@ -56,16 +55,17 @@ protected DynamicObject absolutePath(DynamicObject threadBacktraceLocation,
5655
if (sourceSection == null) {
5756
return coreStrings().UNKNOWN.createInstance();
5857
} else {
59-
final String path = RubyContext.getPath(sourceSection.getSource());
60-
if (new File(path).isAbsolute()) { // A normal file
58+
final Source source = sourceSection.getSource();
59+
final String path = RubyContext.getPath(source);
60+
if (source.getPath() != null) { // A normal file
6161
final String canonicalPath = getContext().getFeatureLoader().canonicalize(path);
6262
final Rope cachedRope = getContext()
6363
.getRopeCache()
6464
.getRope(StringOperations.encodeRope(canonicalPath, UTF8Encoding.INSTANCE));
6565
return makeStringNode.fromRope(cachedRope);
6666
} else { // eval()
6767
return makeStringNode
68-
.fromRope(getContext().getPathToRopeCache().getCachedPath(sourceSection.getSource()));
68+
.fromRope(getContext().getPathToRopeCache().getCachedPath(source));
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)