Skip to content
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

Fix FiltersAggregation NPE when filters is empty #41459

Merged
merged 8 commits into from
May 20, 2019

Conversation

polyfractal
Copy link
Contributor

If keyedFilters is null the code assumes there are unkeyed filters...which will NPE if the unkeyed filters was actually empty.

This refactors to simplify the filter assignment a bit, adds an empty check and tidies up some formatting.

It also fixes a few tests that should have exposed this NPE, but due to how they were setup (using try blocks) the exception was hidden. The try blocks are removed so that any future exceptions are not swallowed.

I wanted to refactor the agg to use our static parsers, but the filters agg is super lenient which makes parsing tricky (anonymous array of filter objects or keyed object of filters, default other bucket name or configurable, boolean to control other bucket which interacts with other key). I think we should probably just simplify the agg... will open a different issue about that.

Closes #41408

If `keyedFilters` is null it assumes there are unkeyed filters...which
will NPE if the unkeyed filters was actually empty.

This refactors to simplify the filter assignment a bit, adds an empty
check and tidies up some formatting.

It also fixes a few tests that _should_ have exposed this NPE, but due
to how they were setup (using try blocks) the exception was hidden.
The try blocks are removed so that any future exceptions are not
swallowed.
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and looks clearer too. One thing I don't follow is where the tests were swallowing the NPE, the try was there only to close the parser when done?

@polyfractal
Copy link
Contributor Author

Huh... yeah you're right. I was thinking the try would swallow exceptions, but it's just acting as a finally for the resources and should rethrow anything inside the try block.

Lemme make sure I'm fixing what I think I'm fixing. :) Going to doublecheck the tests and the original NPE.

@polyfractal
Copy link
Contributor Author

Oh right, I see. The tests don't cover the NPE case... I misread the original query. It's a completely empty filters agg, not an empty filters array/object inside the filters agg.

The fix works as intended because it prevents keyed/unkeyed from being null, but I'll add a test for the empty filter agg, revert the try... changes and adjust the commit message.

@javanna
Copy link
Member

javanna commented Apr 24, 2019

sounds good thanks @polyfractal !

@polyfractal
Copy link
Contributor Author

polyfractal commented Apr 25, 2019

@elasticmachine run elasticsearch-ci/1

@polyfractal
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/default-distro
@elasticmachine run elasticsearch-ci/bwc

@polyfractal
Copy link
Contributor Author

CI is green but a bit stale for my liking and I've been bit by that recently, sooo....

@elasticmachine retest this please

@polyfractal polyfractal merged commit 0635f5a into elastic:master May 20, 2019
polyfractal added a commit that referenced this pull request May 20, 2019
If `keyedFilters` is null it assumes there are unkeyed filters...which
will NPE if the unkeyed filters was actually empty.

This refactors to simplify the filter assignment a bit, adds an empty
check and tidies up some formatting.
gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this pull request May 27, 2019
If `keyedFilters` is null it assumes there are unkeyed filters...which
will NPE if the unkeyed filters was actually empty.

This refactors to simplify the filter assignment a bit, adds an empty
check and tidies up some formatting.
codebrain added a commit to elastic/elasticsearch-net that referenced this pull request Jul 17, 2019
Elasticsearch 7.2.0 introduced a change to empty filters handling in elastic/elasticsearch#41459
russcam pushed a commit to elastic/elasticsearch-net that referenced this pull request Jul 18, 2019
Elasticsearch 7.2.0 introduced a change to empty filters handling in elastic/elasticsearch#41459
russcam pushed a commit to elastic/elasticsearch-net that referenced this pull request Jul 18, 2019
Elasticsearch 7.2.0 introduced a change to empty filters handling in elastic/elasticsearch#41459

(cherry picked from commit a8e502f)
russcam pushed a commit to elastic/elasticsearch-net that referenced this pull request Jul 18, 2019
Elasticsearch 7.2.0 introduced a change to empty filters handling in elastic/elasticsearch#41459

(cherry picked from commit a8e502f)
codebrain added a commit to elastic/elasticsearch-net that referenced this pull request Jul 19, 2019
Elasticsearch 7.2.0 introduced a change to empty filters handling in elastic/elasticsearch#41459

(cherry picked from commit a8e502f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

null_pointer_exception when filters aggregation is empty
4 participants