Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b334ad5

Browse files
committedMar 19, 2018
Reverse the order in which we print out the backtrace. #4876
1 parent 4cf9456 commit b334ad5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/runtime/backtrace/TraceType.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static void logBacktrace(RubyStackTraceElement[] trace) {
6969

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

72-
renderBacktraceJRuby(trace, buffer, false);
72+
renderBacktraceJRuby(trace, buffer, false, Direction.Forward);
7373

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

300300
public void renderBacktrace(RubyStackTraceElement[] elts, StringBuilder buffer, boolean color) {
301-
renderBacktraceJRuby(elts, buffer, color);
301+
renderBacktraceJRuby(elts, buffer, color, Direction.Reverse);
302302
}
303303
};
304304

@@ -388,9 +388,9 @@ public static String printBacktraceJRuby(RubyStackTraceElement[] frames, String
388388

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

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

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

395395
return buffer.toString();
396396
}
@@ -412,7 +412,9 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
412412
return printBacktraceJRuby(frames, type, message, color);
413413
}
414414

415-
private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringBuilder buffer, boolean color) {
415+
private enum Direction { Forward, Reverse };
416+
417+
private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringBuilder buffer, boolean color, Direction direction) {
416418
// find longest method name
417419
int longestMethod = 0;
418420
for (RubyStackTraceElement frame : frames) {
@@ -421,7 +423,8 @@ private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringB
421423

422424
// backtrace lines
423425
boolean first = true;
424-
for (RubyStackTraceElement frame : frames) {
426+
for (int i = 0; i < frames.length; i++) {
427+
RubyStackTraceElement frame = direction == Direction.Forward ? frames[i] : frames[frames.length - i - 1];
425428
if (color) {
426429
if (first) {
427430
buffer.append(FIRST_COLOR);

0 commit comments

Comments
 (0)
Please sign in to comment.