You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "M Kim (JIRA)" <ji...@apache.org> on 2015/02/16 19:36:18 UTC

[jira] [Updated] (LUCENE-5876) NPE in BoostQueryNodeBuilder.build

     [ https://issues.apache.org/jira/browse/LUCENE-5876?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

M Kim updated LUCENE-5876:
--------------------------
    Description: 
{code}
  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;

  }
{code}
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>
{code}
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);
}
{code}
<Stack Trace>
{code}
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)
{code}

  was:
  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>
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>
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)


> NPE in BoostQueryNodeBuilder.build
> ----------------------------------
>
>                 Key: LUCENE-5876
>                 URL: https://issues.apache.org/jira/browse/LUCENE-5876
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: core/queryparser
>    Affects Versions: 4.9
>            Reporter: M Kim
>
> {code}
>   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;
>   }
> {code}
> 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>
> {code}
> 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);
> }
> {code}
> <Stack Trace>
> {code}
> 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)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org