Apache Lucene open-source search software
LUCENE-7567: don't clone BooleanClause in builder
yonikb426838e8f24
diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.javaindex e67d7f4cc53..2ea0d0e94e9 100644--- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java+++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java@@ -109,7 +109,10 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {* @throws TooManyClauses if the new number of clauses exceeds the maximum clause number*/public Builder add(BooleanClause clause) {- add(clause.getQuery(), clause.getOccur());+ if (clauses.size() >= maxClauseCount) {+ throw new TooManyClauses();+ }+ clauses.add(clause);return this;}@@ -120,11 +123,7 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {* @throws TooManyClauses if the new number of clauses exceeds the maximum clause number*/public Builder add(Query query, Occur occur) {- if (clauses.size() >= maxClauseCount) {- throw new TooManyClauses();- }- clauses.add(new BooleanClause(query, occur));- return this;+ return add(new BooleanClause(query, occur));}/** Create a new {@link BooleanQuery} based on the parameters that have