diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/builders/QueryTreeBuilder.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/builders/QueryTreeBuilder.java index 25f2ecd9948..7fc916ec663 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/builders/QueryTreeBuilder.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/builders/QueryTreeBuilder.java @@ -150,7 +150,7 @@ public class QueryTreeBuilder implements QueryBuilder { builder = getQueryBuilder(clazz); if (builder == null) { - Class[] classes = node.getClass().getInterfaces(); + Class[] classes = clazz.getInterfaces(); for (Class actualClass : classes) { builder = getQueryBuilder(actualClass); diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java index 2fe5e918c7a..e837a53868b 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/core/builders/TestQueryTreeBuilder.java @@ -22,6 +22,8 @@ import junit.framework.Assert; import org.apache.lucene.queryparser.flexible.core.QueryNodeException; import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode; import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode; +import org.apache.lucene.queryparser.flexible.core.nodes.QueryNodeImpl; +import org.apache.lucene.queryparser.flexible.core.parser.EscapeQuerySyntax; import org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence; import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; @@ -35,6 +37,28 @@ public class TestQueryTreeBuilder extends LuceneTestCase { Object result = qtb.build(new FieldQueryNode(new UnescapedCharSequence("field"), "foo", 0, 0)); Assert.assertEquals("OK", result); + // LUCENE-4890 + qtb = new QueryTreeBuilder(); + qtb.setBuilder(DummyQueryNodeInterface.class, new DummyBuilder()); + result = qtb.build(new DummyQueryNode()); + Assert.assertEquals("OK", result); + } + + private static interface DummyQueryNodeInterface extends QueryNode { + + } + + private static abstract class AbstractDummyQueryNode extends QueryNodeImpl implements DummyQueryNodeInterface { + + } + + private static class DummyQueryNode extends AbstractDummyQueryNode { + + @Override + public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) { + return "DummyQueryNode"; + } + } private static class DummyBuilder implements QueryBuilder {