Skip to content

Commit

Permalink
Separate two types of internal check
Browse files Browse the repository at this point in the history
* Starting with uri:classloader:/jruby/kernel are filenames that
  come from JRuby's internal Ruby sources. They should gain the
  internal prefix.
* Starting with internal prefix indicates an internal source that
  may be appropriate to exclude under certain conditions.

We check both of these at trace-construction time because the
relevant rubyspec shows the behavior to also filter out user-
provided filenames with the same internal prefix, which is used
to test the masking and removal of these lines. In order to
handle both true internal filenames and user-provided internal-
prefixed filenames, both must be checked for omission here.

I don't agree with the side effect of being able to mask any trace
line, but I think that train has sailed.
  • Loading branch information
headius committed Nov 8, 2023
1 parent 71b568a commit 26bb39e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.headius.backport9.stack.StackWalker;
import org.jruby.Ruby;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.JavaNameMangler;

import java.io.Serializable;
Expand Down Expand Up @@ -93,7 +92,7 @@ private RubyStackTraceElement[] constructBacktrace(Map<String, Map<String, Strin
// Only rewrite non-Java files when not in "raw" mode
if (!(rawTrace || filename == null || filename.endsWith(".java"))) {
// skip internal sources if requested
if (excludeInternal && TraceType.isInternal(filename)) continue;
if (excludeInternal && TraceType.isExcludedInternal(filename)) continue;

List<String> mangledTuple = JavaNameMangler.decodeMethodTuple(methodName);
if (mangledTuple != null) {
Expand Down Expand Up @@ -173,7 +172,7 @@ private RubyStackTraceElement[] constructBacktrace(Map<String, Map<String, Strin

// skip internal sources if requested
filename = rubyFrame.filename;
if (excludeInternal && TraceType.isInternal(filename)) continue;
if (excludeInternal && TraceType.isExcludedInternal(filename)) continue;

// mask internal file paths
filename = TraceType.maskInternalFiles(filename);
Expand Down
15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/runtime/backtrace/TraceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,23 @@ public static IRubyObject generateMRIBacktrace(Ruby runtime, RubyStackTraceEleme
}

public static String maskInternalFiles(String filename) {
if (isInternal(filename)) {
if (isInternalFile(filename)) {
return "<internal:" + filename + ">";
}

return filename;
}

public static boolean isInternal(String filename) {
return filename.startsWith("uri:classloader:/jruby/kernel/") ||
filename.startsWith("<internal:");
public static boolean isInternalFile(String filename) {
return filename.startsWith("uri:classloader:/jruby/kernel/");
}

public static boolean hasInternalMarker(String filename) {
return filename.startsWith("<internal:");
}

public static boolean isExcludedInternal(String filename) {
return TraceType.isInternalFile(filename) || TraceType.hasInternalMarker(filename);
}

@Deprecated
Expand Down

0 comments on commit 26bb39e

Please sign in to comment.