Skip to content

Commit

Permalink
Reverse the order in which we print out the backtrace. #4876
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 19, 2018
1 parent 4cf9456 commit b334ad5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions core/src/main/java/org/jruby/runtime/backtrace/TraceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void logBacktrace(RubyStackTraceElement[] trace) {

buffer.append("Backtrace generated:\n");

renderBacktraceJRuby(trace, buffer, false);
renderBacktraceJRuby(trace, buffer, false, Direction.Forward);

// NOTE: other logXxx method do not remove the new-line
// ... but if this is desired they should do so as well
Expand Down Expand Up @@ -298,7 +298,7 @@ public String printBacktrace(RubyException exception, boolean console) {
}

public void renderBacktrace(RubyStackTraceElement[] elts, StringBuilder buffer, boolean color) {
renderBacktraceJRuby(elts, buffer, color);
renderBacktraceJRuby(elts, buffer, color, Direction.Reverse);
}
};

Expand Down Expand Up @@ -388,9 +388,9 @@ public static String printBacktraceJRuby(RubyStackTraceElement[] frames, String

StringBuilder buffer = new StringBuilder(64 + frames.length * 48);

buffer.append(type).append(": ").append(message).append('\n');
renderBacktraceJRuby(frames, buffer, color, Direction.Reverse);

renderBacktraceJRuby(frames, buffer, color);
buffer.append(type).append(": ").append(message).append('\n');

return buffer.toString();
}
Expand All @@ -412,7 +412,9 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
return printBacktraceJRuby(frames, type, message, color);
}

private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringBuilder buffer, boolean color) {
private enum Direction { Forward, Reverse };

private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringBuilder buffer, boolean color, Direction direction) {
// find longest method name
int longestMethod = 0;
for (RubyStackTraceElement frame : frames) {
Expand All @@ -421,7 +423,8 @@ private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringB

// backtrace lines
boolean first = true;
for (RubyStackTraceElement frame : frames) {
for (int i = 0; i < frames.length; i++) {
RubyStackTraceElement frame = direction == Direction.Forward ? frames[i] : frames[frames.length - i - 1];
if (color) {
if (first) {
buffer.append(FIRST_COLOR);
Expand Down

0 comments on commit b334ad5

Please sign in to comment.