[TEST] fix NPE when generating random query (#26023)

`ClusterSearchShardsResponseTests.testSerialization` randomly uses `IdsQueryBuilderTests` to generate an alias filter. `IdsQueryBuilderTests` shecks if the array of current types is length zero but it can also be null which causes a `NullPointerException`. This changes adds a null check to avoid the exception.

Closes #26021
This commit is contained in:
Colin Goodheart-Smithe 2017-08-02 18:28:26 +01:00 committed by GitHub
parent bb3d5b7426
commit aafd7f90fd

View File

@ -20,9 +20,9 @@
package org.elasticsearch.index.query;
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermInSetQuery;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.index.mapper.UidFieldMapper;
@ -39,7 +39,7 @@ public class IdsQueryBuilderTests extends AbstractQueryTestCase<IdsQueryBuilder>
@Override
protected IdsQueryBuilder doCreateTestQueryBuilder() {
String[] types;
if (getCurrentTypes().length > 0 && randomBoolean()) {
if (getCurrentTypes() != null && getCurrentTypes().length > 0 && randomBoolean()) {
int numberOfTypes = randomIntBetween(1, getCurrentTypes().length);
types = new String[numberOfTypes];
for (int i = 0; i < numberOfTypes; i++) {