Skip to content

Commit b17ae6b

Browse files
committed
Fix: stack trace may be null.
1 parent 1c5f483 commit b17ae6b

File tree

1 file changed

+25
-23
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception

1 file changed

+25
-23
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,34 @@ private ExceptionUtils() {
5757
@TruffleBoundary
5858
public static void printPythonLikeStackTrace(Throwable e) {
5959
List<TruffleStackTraceElement> stackTrace = TruffleStackTrace.getStackTrace(e);
60-
ArrayList<String> stack = new ArrayList<>();
61-
for (TruffleStackTraceElement frame : stackTrace) {
60+
if (stackTrace != null) {
61+
ArrayList<String> stack = new ArrayList<>();
62+
for (TruffleStackTraceElement frame : stackTrace) {
6263

63-
StringBuilder sb = new StringBuilder();
64-
Node location = frame.getLocation();
65-
SourceSection sourceSection = location != null ? location.getSourceSection() : null;
66-
String rootName = frame.getTarget().getRootNode().getName();
67-
if (sourceSection != null) {
68-
sb.append(" ");
69-
String path = sourceSection.getSource().getPath();
70-
if (path != null) {
71-
sb.append("File ");
64+
StringBuilder sb = new StringBuilder();
65+
Node location = frame.getLocation();
66+
SourceSection sourceSection = location != null ? location.getSourceSection() : null;
67+
String rootName = frame.getTarget().getRootNode().getName();
68+
if (sourceSection != null) {
69+
sb.append(" ");
70+
String path = sourceSection.getSource().getPath();
71+
if (path != null) {
72+
sb.append("File ");
73+
}
74+
sb.append('"');
75+
sb.append(sourceSection.getSource().getName());
76+
sb.append("\", line ");
77+
sb.append(sourceSection.getStartLine());
78+
sb.append(", in ");
79+
sb.append(rootName);
80+
stack.add(sb.toString());
7281
}
73-
sb.append('"');
74-
sb.append(sourceSection.getSource().getName());
75-
sb.append("\", line ");
76-
sb.append(sourceSection.getStartLine());
77-
sb.append(", in ");
78-
sb.append(rootName);
79-
stack.add(sb.toString());
8082
}
81-
}
82-
System.err.println("Traceback (most recent call last):");
83-
ListIterator<String> listIterator = stack.listIterator(stack.size());
84-
while (listIterator.hasPrevious()) {
85-
System.err.println(listIterator.previous());
83+
System.err.println("Traceback (most recent call last):");
84+
ListIterator<String> listIterator = stack.listIterator(stack.size());
85+
while (listIterator.hasPrevious()) {
86+
System.err.println(listIterator.previous());
87+
}
8688
}
8789
System.err.println(e.getMessage());
8890
}

0 commit comments

Comments
 (0)