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

Handle NPE due to a weird configuration #48007

Closed
wants to merge 1 commit into from
Closed

Handle NPE due to a weird configuration #48007

wants to merge 1 commit into from

Conversation

ebuildy
Copy link
Contributor

@ebuildy ebuildy commented Oct 14, 2019

Prevent java.lang.NullPointerException. To reproduce: set max_query_terms to 0 and you get:

"Caused by: java.lang.NullPointerException",
"at org.elasticsearch.common.lucene.search.XMoreLikeThis.createQueue(XMoreLikeThis.java:766) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.XMoreLikeThis.createQueue(XMoreLikeThis.java:716) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.XMoreLikeThis.like(XMoreLikeThis.java:630) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.MoreLikeThisQuery.createQuery(MoreLikeThisQuery.java:172) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.MoreLikeThisQuery.rewrite(MoreLikeThisQuery.java:156) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.apache.lucene.search.IndexSearcher.rewrite(IndexSearcher.java:667) ~[lucene-core-8.1.0.jar:8.1.0 dbe5ed0b2f17677ca6c904ebae919363f2d36a0a - ishan - 2019-05-09 19:34:03]",
"at org.elasticsearch.search.internal.ContextIndexSearcher.rewrite(ContextIndexSearcher.java:110) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.DefaultSearchContext.preProcess(DefaultSearchContext.java:263) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.query.QueryPhase.preProcess(QueryPhase.java:91) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.createContext(SearchService.java:603) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:550) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:353) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.lambda$executeQueryPhase$1(SearchService.java:340) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.action.ActionListener.lambda$map$2(ActionListener.java:145) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:62) ~[elasticsearch-7.3.1.jar:7.3.1]",
"... 8 more"] }
  • Have you signed the contributor license agreement?
  • Have you followed the contributor guidelines?
  • If submitting code, have you built your formula locally prior to submission with gradle check?
  • If submitting code, is your pull request against master? Unless there is a good reason otherwise, we prefer pull requests against master and will backport as needed.
  • If submitting code, have you checked that your submission is for an OS and architecture that we support?
  • If you are submitting this code for a class then read our policy for that.

Prevent ``java.lang.NullPointerException``.  To reproduce:  set ``max_query_terms`` to 0 and you get:

```
"Caused by: java.lang.NullPointerException",
"at org.elasticsearch.common.lucene.search.XMoreLikeThis.createQueue(XMoreLikeThis.java:766) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.XMoreLikeThis.createQueue(XMoreLikeThis.java:716) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.XMoreLikeThis.like(XMoreLikeThis.java:630) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.MoreLikeThisQuery.createQuery(MoreLikeThisQuery.java:172) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.common.lucene.search.MoreLikeThisQuery.rewrite(MoreLikeThisQuery.java:156) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.apache.lucene.search.IndexSearcher.rewrite(IndexSearcher.java:667) ~[lucene-core-8.1.0.jar:8.1.0 dbe5ed0b2f17677ca6c904ebae919363f2d36a0a - ishan - 2019-05-09 19:34:03]",
"at org.elasticsearch.search.internal.ContextIndexSearcher.rewrite(ContextIndexSearcher.java:110) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.DefaultSearchContext.preProcess(DefaultSearchContext.java:263) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.query.QueryPhase.preProcess(QueryPhase.java:91) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.createContext(SearchService.java:603) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:550) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:353) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.search.SearchService.lambda$executeQueryPhase$1(SearchService.java:340) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.action.ActionListener.lambda$map$2(ActionListener.java:145) ~[elasticsearch-7.3.1.jar:7.3.1]",
"at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:62) ~[elasticsearch-7.3.1.jar:7.3.1]",
"... 8 more"] }
```
@williamrandolph
Copy link
Contributor

@elasticmachine test this please

@williamrandolph williamrandolph added the :Search/Search Search-related issues that do not fall into other categories label Oct 14, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

Hi @ebuildy,

thanks for the PR, I'd like to understand how you ran into this particular NPE and would rather catch it earlier on by checking the input parameters and add vaidation checks / throw IAE in the builders and query itself before we even get to constructing a query. Does this make sense or am I missing that would make max_query_terms of 0 (or even negative) a setting we should to support?


if (limit == 0) {
return queue;
}
Copy link
Member

Choose a reason for hiding this comment

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

Rather than checking for a particular value this late, I'd rather try improving the input validation for the max_query_terms parameter, both in the MoreLikeThisQueryBuilder setter and also maybe in MoreLikeThisQuery. I think we should reject negative or zero values here, since at least to my understanding it indicates a wrong usage of the API. Or are there cases you know where this parameter setting would make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree there is no sense to set max_query_terms = 0, maybe the API should validate this parameter instead.

Copy link
Member

Choose a reason for hiding this comment

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

Are you interested in changing this PR to add validation to the MoreLikeThisQueryBuilder and MoreLikeThisQuery setters for the max query terms? I think we should reject all values <= 0 there already with an IllegalArgumentException and a fitting message. Adding these checkes should also be tests in the corresponding unit tests. If you don't want to do this just let me know, I'll open an issue so we can fix it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! thanks you

@cbuescher cbuescher self-assigned this Oct 15, 2019
@cbuescher
Copy link
Member

Hi @ebuildy, just checking in to see if you are still interested in working on this PR. If you are busy and cannot continue working on it we can also open an issue and somebody else can pick it up.

@ebuildy
Copy link
Contributor Author

ebuildy commented Dec 6, 2019

hello @cbuescher I am quite busy by this end of the year, if someone can work on it this would be perfect, sorry for my late.

@cbuescher
Copy link
Member

@ebuildy no problem, thanks for getting back. I opened #49927 and will close this PR then, but feel free to pick it up once you have time if it is still open.

@cbuescher cbuescher closed this Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants