diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java b/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java index 9eae902c3e3..52b531e5cd1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java @@ -88,6 +88,9 @@ public class Stash implements ToXContent { */ public Object unstashValue(String value) throws IOException { if (value.startsWith("$body.")) { + if (response == null) { + return null; + } return response.evaluate(value.substring("$body".length()), this); } Object stashedValue = stash.get(value.substring(1)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java index cdcd6a21a52..e0b2f3ab729 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestResponse.java @@ -51,7 +51,11 @@ public class RestResponse { */ public Object getBody() throws IOException { if (isJson()) { - return parsedResponse().evaluate(""); + JsonPath parsedResponse = parsedResponse(); + if (parsedResponse == null) { + return null; + } + return parsedResponse.evaluate(""); } return response.getBody(); }