From 79090431af1a6d9a1945a316968bf21cc66a4386 Mon Sep 17 00:00:00 2001 From: Yuhao Bi Date: Wed, 2 Nov 2016 00:25:20 +0800 Subject: [PATCH] Provide error message when request path is null --- .../java/org/elasticsearch/client/RestClient.java | 1 + .../elasticsearch/client/RestClientIntegTests.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java index d2301e1e8e7..b8eb98b4aee 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java +++ b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java @@ -510,6 +510,7 @@ public class RestClient implements Closeable { private static URI buildUri(String pathPrefix, String path, Map params) { Objects.requireNonNull(params, "params must not be null"); + Objects.requireNonNull(path, "path must not be null"); try { String fullPath; if (pathPrefix != null) { diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java index 9c5c50946d8..941af2246f8 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientIntegTests.java @@ -229,6 +229,17 @@ public class RestClientIntegTests extends RestClientTestCase { } } + public void testPath() throws IOException { + for (String method : getHttpMethods()) { + try { + restClient.performRequest(method, null); + fail("path set to null should fail!"); + } catch (NullPointerException e) { + assertEquals("path must not be null", e.getMessage()); + } + } + } + private void bodyTest(String method) throws IOException { String requestBody = "{ \"field\": \"value\" }"; StringEntity entity = new StringEntity(requestBody);