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:
Andriy Redko 2022-04-22 16:31:14 -04:00 committed by GitHub
parent f006afa969
commit f438561615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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);

View File

@ -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));