apache / apache/lucene

Null value dereference [LUCENE-6602]

Open
#7,660 1 comment 0 reactions 0 assignees View on GitHub
affects-version:6.0 legacy-jira-label:github-pullrequest legacy-jira-priority:Minor module:queryparser type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

In the file `BoostQueryNode.java`, `getChild` could be null and it is being dereferenced in the function `toString()`.

```Java
public QueryNode getChild() {
List children = getChildren();

if (children == null || children.size() == 0) {
return null;
}

return children.get(0);

}
```

```Java
public String toString() {
return "" + "\n"
+ getChild().toString() + "\n";
}
```

Should we not check if getChild is valid?

```Java
String s = (getChild() != null) ? getChild().toString() : "null";
return "" + "\n"
+ s + "\n";
```

---
Migrated from [LUCENE-6602](https://issues.apache.org/jira/browse/LUCENE-6602) by Rishabh Patel, updated May 09 2016

Contributor guide

Open the contributing guide

Research direction

Open BoostQueryNode.java and inspect getChild() alongside toString(), focusing on the null-child path described in the issue. Verify the behavior for a node with no child, then confirm that toString() no longer dereferences null and produces the intended output.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.