Skip to content

Commit 462a529

Browse files
committed
Fix NullPointerException in LongComparator caused by null search_after values
1 parent fc09858 commit 462a529

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

server/src/main/java/org/elasticsearch/search/searchafter/SearchAfterBuilder.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ public static SearchAfterBuilder fromXContent(XContentParser parser) throws IOEx
252252
} else if (token == XContentParser.Token.VALUE_BOOLEAN) {
253253
values.add(parser.booleanValue());
254254
} else if (token == XContentParser.Token.VALUE_NULL) {
255-
throw new ParsingException(
256-
parser.getTokenLocation(),
257-
"Values cannot contain null."
258-
);
255+
throw new ParsingException(parser.getTokenLocation(), "Values cannot contain null.");
259256
} else {
260257
throw new ParsingException(
261258
parser.getTokenLocation(),

server/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,11 @@ public void testBuildFieldDocWithCollapse() {
286286
public void testSetSortValuesRejectsNull() {
287287
SearchAfterBuilder builder = new SearchAfterBuilder();
288288

289-
IllegalArgumentException e1 = expectThrows(IllegalArgumentException.class, () -> {
290-
builder.setSortValues(new Object[]{ null });
291-
});
289+
IllegalArgumentException e1 = expectThrows(IllegalArgumentException.class, () -> { builder.setSortValues(new Object[] { null }); });
292290
assertThat(e1.getMessage(), equalTo("Values cannot contain null at position 0."));
293291

294292
IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> {
295-
builder.setSortValues(new Object[]{ 123L, null, "test" });
293+
builder.setSortValues(new Object[] { 123L, null, "test" });
296294
});
297295
assertThat(e2.getMessage(), equalTo("Values cannot contain null at position 1."));
298296
}
@@ -306,9 +304,7 @@ public void testFromXContentRejectsNull() throws Exception {
306304
parser.nextToken();
307305
parser.nextToken();
308306
parser.nextToken();
309-
ParsingException e = expectThrows(ParsingException.class, () -> {
310-
SearchAfterBuilder.fromXContent(parser);
311-
});
307+
ParsingException e = expectThrows(ParsingException.class, () -> { SearchAfterBuilder.fromXContent(parser); });
312308
assertThat(e.getMessage(), equalTo("Values cannot contain null."));
313309
}
314310
}
@@ -323,7 +319,7 @@ public void testBuildFieldDocRejectsNull() {
323319
SortAndFormats sortAndFormats = new SortAndFormats(sort, formats);
324320

325321
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
326-
SearchAfterBuilder.buildFieldDoc(sortAndFormats, new Object[]{ null }, null);
322+
SearchAfterBuilder.buildFieldDoc(sortAndFormats, new Object[] { null }, null);
327323
});
328324
assertThat(e.getMessage(), equalTo("Values cannot contain null at position 0."));
329325
}

0 commit comments

Comments
 (0)