-
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?
Conversation
|
Pinging @elastic/es-search-foundations (Team:Search Foundations) |
|
@elasticsearchmachine test this please |
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 left a couple small comments. This looks good to me though, thanks a lot for your contribution!
| fieldValues[i] = convertValueFromSortField(values[i], sortField, format); | ||
| } else { | ||
| fieldValues[i] = null; | ||
| throw new IllegalArgumentException("Values cannot contain null at position " + i + "."); |
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 the sortValues array, bypassing the validation in setSortValues().
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!
| values.add(parser.booleanValue()); | ||
| } else if (token == XContentParser.Token.VALUE_NULL) { | ||
| values.add(null); | ||
| throw new ParsingException(parser.getTokenLocation(), "Values cannot contain null."); |
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.
Should we be more specific in the error message that it's the search_after values?
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.
You're right, that would be much clearer. I think we could update this to:
Values cannot contain null.→[search_after] values cannot contain null.
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.
++
|
test this please |
Change Summary
Fix NullPointerException in LongComparator when search_after contains null values by implementing validation at multiple layers.
As null values in search_after arrays are not valid and cause NPE when passed to Lucene's comparators, this change updates the SearchAfterBuilder to reject null values during JSON parsing, object setting, and FieldDoc creation with clear error messages.
Open to suggestions or corrections!
Related Issue
#132370