Apache Solr open-source search software
Fix ArrayIndexOutOfBoundsExceptions This patch is common to several patches for QueryParser see e.g. Bug 9110 and it cannot have any negative side effects.
Christoph Gollerdfeed0220e6c
diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.java b/src/java/org/apache/lucene/queryParser/QueryParser.javaindex a34e1cf8ac9..bf460007a34 100644--- a/src/java/org/apache/lucene/queryParser/QueryParser.java+++ b/src/java/org/apache/lucene/queryParser/QueryParser.java@@ -177,13 +177,13 @@ public class QueryParser implements QueryParserConstants {// If this term is introduced by AND, make the preceding term required,// unless it's already prohibited- if (conj == CONJ_AND) {+ if (clauses.size() > 0 && conj == CONJ_AND) {BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);if (!c.isProhibited())c.setOccur(BooleanClause.Occur.MUST);}- if (operator == DEFAULT_OPERATOR_AND && conj == CONJ_OR) {+ if (clauses.size() > 0 && operator == DEFAULT_OPERATOR_AND && conj == CONJ_OR) {// If this term is introduced by OR, make the preceding term optional,// unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)// notice if the input is a OR b, first term is parsed as required; withoutdiff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jjindex 3b1fd60216a..c787e4ae568 100644--- a/src/java/org/apache/lucene/queryParser/QueryParser.jj+++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj@@ -200,13 +200,13 @@ public class QueryParser {// If this term is introduced by AND, make the preceding term required,// unless it's already prohibited- if (conj == CONJ_AND) {+ if (clauses.size() > 0 && conj == CONJ_AND) {BooleanClause c = (BooleanClause) clauses.elementAt(clauses.size()-1);if (!c.isProhibited())c.setOccur(BooleanClause.Occur.MUST);}- if (operator == DEFAULT_OPERATOR_AND && conj == CONJ_OR) {+ if (clauses.size() > 0 && operator == DEFAULT_OPERATOR_AND && conj == CONJ_OR) {// If this term is introduced by OR, make the preceding term optional,// unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)// notice if the input is a OR b, first term is parsed as required; without