apache / apache/lucene

NPE in BoostQueryNodeBuilder.build [LUCENE-5876]

Open
#6,938 0 comments 0 reactions 0 assignees View on GitHub
affects-version:4.9 legacy-jira-priority:Major module:core/queryparser type:bug
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.