- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
Fix NullPointerException in LongComparator caused by null search_after values #132434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
fc09858
              462a529
              8b3ed29
              d0139e5
              43071a2
              2a099ca
              dedceaa
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -68,7 +68,9 @@ public SearchAfterBuilder setSortValues(Object[] values) { | |
| throw new IllegalArgumentException("Values must contains at least one value."); | ||
| } | ||
| for (int i = 0; i < values.length; i++) { | ||
| if (values[i] == null) continue; | ||
| if (values[i] == null) { | ||
| throw new IllegalArgumentException("Values cannot contain null at position " + i + "."); | ||
| } | ||
| if (values[i] instanceof String) continue; | ||
| if (values[i] instanceof Text) continue; | ||
| if (values[i] instanceof Long) continue; | ||
|  | @@ -117,7 +119,7 @@ public static FieldDoc buildFieldDoc(SortAndFormats sort, Object[] values, @Null | |
| if (values[i] != null) { | ||
| fieldValues[i] = convertValueFromSortField(values[i], sortField, format); | ||
| } else { | ||
| fieldValues[i] = null; | ||
| throw new IllegalArgumentException("Values cannot contain null at position " + i + "."); | ||
| } | ||
| } | ||
| /* | ||
|  | @@ -250,7 +252,7 @@ public static SearchAfterBuilder fromXContent(XContentParser parser) throws IOEx | |
| } else if (token == XContentParser.Token.VALUE_BOOLEAN) { | ||
| values.add(parser.booleanValue()); | ||
| } else if (token == XContentParser.Token.VALUE_NULL) { | ||
| values.add(null); | ||
| throw new ParsingException(parser.getTokenLocation(), "Values cannot contain null."); | ||
|          | ||
| } else { | ||
| throw new ParsingException( | ||
| parser.getTokenLocation(), | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you know what scenario this covers for in practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the constructor
SearchAfterBuilder(StreamInput in),readGenericValue()can return null (case -1), and these null values are directly assigned to thesortValuesarray, bypassing the validation insetSortValues().Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I see, but these you can only get from a serialized SearchAfterBuilder, so perhaps null values can only come in from previous versions (before your change is made)? At the same time version based logic complicates things so maybe it is ok to leave it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your point about backward compatibility. Keeping the validation as it is seems like the simplest and safest approach. Appreciate the feedback!