Added explicit 'null' check for response listener to prevent obscure NullPointerException issues (#3048)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
This commit is contained in:
parent
f006afa969
commit
f438561615
|
@ -1917,6 +1917,10 @@ public class RestHighLevelClient implements Closeable {
|
||||||
ActionListener<Resp> listener,
|
ActionListener<Resp> listener,
|
||||||
Set<Integer> ignores
|
Set<Integer> ignores
|
||||||
) {
|
) {
|
||||||
|
if (listener == null) {
|
||||||
|
throw new IllegalArgumentException("The listener is required and cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
Request req;
|
Request req;
|
||||||
try {
|
try {
|
||||||
req = requestConverter.apply(request);
|
req = requestConverter.apply(request);
|
||||||
|
|
|
@ -284,6 +284,20 @@ public class RestHighLevelClientTests extends OpenSearchTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNullableActionListener() {
|
||||||
|
ActionRequest request = new ActionRequest() {
|
||||||
|
@Override
|
||||||
|
public ActionRequestValidationException validate() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> restHighLevelClient.performRequestAsync(request, null, RequestOptions.DEFAULT, null, null, null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public void testParseEntity() throws IOException {
|
public void testParseEntity() throws IOException {
|
||||||
{
|
{
|
||||||
IllegalStateException ise = expectThrows(IllegalStateException.class, () -> restHighLevelClient.parseEntity(null, null));
|
IllegalStateException ise = expectThrows(IllegalStateException.class, () -> restHighLevelClient.parseEntity(null, null));
|
||||||
|
|
Loading…
Reference in New Issue