NPE in BoostQueryNodeBuilder.build [LUCENE-5876]
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
```Java
public Query build(QueryNode queryNode) throws QueryNodeException {
BoostQueryNode boostNode = (BoostQueryNode) queryNode;
QueryNode child = boostNode.getChild();
if (child == null) {
return null;
}
Query query = (Query) child
.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
query.setBoost(boostNode.getValue());
return query;
}
```
In BoostQueryNodeBuilder.build, the return variable, "query" can be null, but there is no error handling code for the return variable. I think there should be a null checker for query like for child.
<Test Case>
```Java
public void test1() throws Throwable {
BoostQueryNodeBuilder builder = new BoostQueryNodeBuilder();
QuotedFieldQueryNode quotedNode = new QuotedFieldQueryNode((java.lang.CharSequence)"hi!", (java.lang.CharSequence)"", 10, 100);
BoostQueryNode node = new BoostQueryNode((QueryNode)quotedNode, 2.0f);
builder.build((QueryNode)node);
}
```
<Stack Trace>
```Java
1) test1(Test0)java.lang.NullPointerException
at org.apache.lucene.queryparser.flexible.standard.builders.BoostQueryNodeBuilder.build(BoostQueryNodeBuilder.java:49)
at Test0.test1(Test0.java:4809)
```
---
Migrated from [LUCENE-5876](https://issues.apache.org/jira/browse/LUCENE-5876) by M Kim, updated Feb 16 2015
Contributor guide
Research direction
Start in BoostQueryNodeBuilder.java at the build method and reproduce the supplied test case, checking how a null query tag reaches the failing line. Confirm the expected handling for that case and add coverage for it; done means the test no longer produces the reported NullPointerException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100