From 8fb9523de540e6748cae0505b8d6853be5828135 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 4 Mar 2011 15:58:10 -0700 Subject: [PATCH] don't try to print null exception trace in printTrace It is possible to create an Exception with no stack trace by overriding Throwable.fillInStackTrace, so we can't assume any given instance will have one. --- src/machine.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index a561006ca7..1f4e895148 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3904,26 +3904,28 @@ printTrace(Thread* t, object exception) } object trace = throwableTrace(t, e); - for (unsigned i = 0; i < objectArrayLength(t, trace); ++i) { - object e = objectArrayBody(t, trace, i); - const int8_t* class_ = &byteArrayBody - (t, className(t, methodClass(t, traceElementMethod(t, e))), 0); - const int8_t* method = &byteArrayBody - (t, methodName(t, traceElementMethod(t, e)), 0); - int line = t->m->processor->lineNumber - (t, traceElementMethod(t, e), traceElementIp(t, e)); + if (trace) { + for (unsigned i = 0; i < objectArrayLength(t, trace); ++i) { + object e = objectArrayBody(t, trace, i); + const int8_t* class_ = &byteArrayBody + (t, className(t, methodClass(t, traceElementMethod(t, e))), 0); + const int8_t* method = &byteArrayBody + (t, methodName(t, traceElementMethod(t, e)), 0); + int line = t->m->processor->lineNumber + (t, traceElementMethod(t, e), traceElementIp(t, e)); - fprintf(stderr, " at %s.%s ", class_, method); + fprintf(stderr, " at %s.%s ", class_, method); - switch (line) { - case NativeLine: - fprintf(stderr, "(native)\n"); - break; - case UnknownLine: - fprintf(stderr, "(unknown line)\n"); - break; - default: - fprintf(stderr, "(line %d)\n", line); + switch (line) { + case NativeLine: + fprintf(stderr, "(native)\n"); + break; + case UnknownLine: + fprintf(stderr, "(unknown line)\n"); + break; + default: + fprintf(stderr, "(line %d)\n", line); + } } }