Skip to content

Commit

Permalink
[TEST] fix NPE when generating random query (#26023)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
colings86 authored Aug 2, 2017
1 parent bb3d5b7 commit aafd7f9
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++) {
Expand Down

0 comments on commit aafd7f9

Please sign in to comment.