Skip to content

Commit 88e08c8

Browse files
committed
Handle null values in stack traces when marshalling exceptions
This should be a little more robust.
1 parent f49083f commit 88e08c8

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

java/server/src/org/openqa/selenium/remote/server/ExceptionHandler.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
import com.google.common.base.Throwables;
2525
import com.google.common.collect.ImmutableList;
26-
import com.google.gson.Gson;
27-
import com.google.gson.JsonObject;
28-
import com.google.gson.JsonPrimitive;
2926

3027
import org.openqa.selenium.WebDriverException;
3128
import org.openqa.selenium.remote.BeanToJsonConverter;
@@ -74,18 +71,18 @@ public void execute(HttpRequest req, HttpResponse resp) {
7471

7572
// JSON Wire Protocol
7673
toSerialise.put("status", code);
77-
value.put(
78-
"stackTrace",
79-
Stream.of(exception.getStackTrace())
80-
.map(ste -> {
81-
JsonObject line = new JsonObject();
82-
line.add("fileName", new JsonPrimitive(ste.getFileName()));
83-
line.add("lineNumber", new JsonPrimitive(ste.getLineNumber()));
84-
line.add("className", new JsonPrimitive(ste.getClassName()));
85-
line.add("methodName", new JsonPrimitive(ste.getMethodName()));
86-
return ste;
87-
})
88-
.collect(ImmutableList.toImmutableList()));
74+
value.put(
75+
"stackTrace",
76+
Stream.of(exception.getStackTrace())
77+
.map(ste -> {
78+
HashMap<String, Object> line = new HashMap<>();
79+
line.put("fileName", ste.getFileName());
80+
line.put("lineNumber", ste.getLineNumber());
81+
line.put("className", ste.getClassName());
82+
line.put("methodName", ste.getMethodName());
83+
return line;
84+
})
85+
.collect(ImmutableList.toImmutableList()));
8986

9087
toSerialise.put("value", value);
9188

0 commit comments

Comments
 (0)