You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Trejkaz (JIRA)" <ji...@apache.org> on 2016/04/29 03:03:12 UTC

[jira] [Updated] (LUCENE-7266) QueryNode#cloneTree produces a new tree where parents are not correctly set

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

Trejkaz updated LUCENE-7266:
----------------------------
    Affects Version/s: 5.4.1

> QueryNode#cloneTree produces a new tree where parents are not correctly set
> ---------------------------------------------------------------------------
>
>                 Key: LUCENE-7266
>                 URL: https://issues.apache.org/jira/browse/LUCENE-7266
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: modules/queryparser
>    Affects Versions: 5.4.1
>            Reporter: Trejkaz
>
> The following unit test performs a sanity check on the QueryNode tree, checking that each node has the parent set to the same node it was retrieved from. After calling cloneTree, this check fails on the returned node, as the parents in the cloned node still point back into the original tree.
> {code}
> import java.util.Arrays;
> import java.util.List;
> import org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode;
> import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode;
> import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;
> import org.junit.Test;
> public class TestCloneTree {
>     @Test
>     public void testCloneTree() throws Exception {
>         QueryNode original = new BooleanQueryNode(Arrays.asList(
>                 new FieldQueryNode(null, "a", 0, 0),
>                 new FieldQueryNode(null, "b", 0, 0)));
>         sanityCheckQueryTree(original);
>         QueryNode cloned = original.cloneTree();
>         sanityCheckQueryTree(cloned);
>     }
>     private void sanityCheckQueryTree(QueryNode node) {
>         List<QueryNode> children = node.getChildren();
>         if (children != null) {
>             for (QueryNode child : children) {
>                 // Matching what Lucene is using in QueryNodeImpl itself.
>                 //noinspection ObjectEquality
>                 if (child.getParent() != node) {
>                     throw new IllegalStateException("Sanity check failed for child: " + child + '\n' +
>                                                     "  Parent is: " + child.getParent() + '\n' +
>                                                     "  But we got to it via: " + node);
>                 }
>                 sanityCheckQueryTree(child);
>             }
>         }
>     }
> }
> {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