Skip to content

Commit

Permalink
improved error message for NPE (see #868)
Browse files Browse the repository at this point in the history
  • Loading branch information
peq committed Jun 22, 2019
1 parent 438757f commit 7ba7167
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ public InterpreterException(Element trace, String msg, Throwable e) {
}

@Override
public String toString() {
if (trace == null) {
return getMessage();
public String getMessage() {
String res = super.getMessage();
if (trace != null) {
WPos pos = trace.attrSource();
res = res + "\n at " + pos.getFile() + " line " + pos.getLine();
}
WPos pos = trace.attrSource();
return "at " + pos.print() + ":\n" + getMessage()
return res;
}

@Override
public String toString() {
return getMessage()
+ (stackTrace != null ? "\nStack trace:\n" + stackTrace : "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static ILconst eval(ImVarArrayAccess e, ProgramState globalState, LocalSt
public static ILconst eval(ImMemberAccess ma, ProgramState globalState, LocalState localState) {
ILconstObject receiver = globalState.toObject(ma.getReceiver().evaluate(globalState, localState));
if (receiver == null) {
throw new RuntimeException("Null pointer dereference");
throw new InterpreterException(ma.getTrace(), "Null pointer dereference");
}
List<Integer> indexes = ma.getIndexes().stream()
.map(i -> ((ILconstInt) i.evaluate(globalState, localState)).getVal())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public String toString() {
}

public String print() {
return "[" + file + ", line " + getLine() + "]";
return "[" + file + " line " + getLine() + "]";
}

public String printShort() {
Expand Down

0 comments on commit 7ba7167

Please sign in to comment.