diff --git a/src/java/org/apache/lucene/search/BooleanQuery.java b/src/java/org/apache/lucene/search/BooleanQuery.java index 85f231e04da..279cbc32f34 100644 --- a/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/src/java/org/apache/lucene/search/BooleanQuery.java @@ -63,6 +63,8 @@ public class BooleanQuery extends Query { * the operating system. */ public static void setMaxClauseCount(int maxClauseCount) { + if (maxClauseCount < 1) + throw new IllegalArgumentException("maxClauseCount must be >= 1"); BooleanQuery.maxClauseCount = maxClauseCount; } diff --git a/src/test/org/apache/lucene/search/TestBooleanQuery.java b/src/test/org/apache/lucene/search/TestBooleanQuery.java index a569abc35b1..04083af3e00 100644 --- a/src/test/org/apache/lucene/search/TestBooleanQuery.java +++ b/src/test/org/apache/lucene/search/TestBooleanQuery.java @@ -20,6 +20,7 @@ import junit.framework.TestCase; import org.apache.lucene.index.Term; public class TestBooleanQuery extends TestCase { + public void testEquality() throws Exception { BooleanQuery bq1 = new BooleanQuery(); bq1.add(new TermQuery(new Term("field", "value1")), BooleanClause.Occur.SHOULD); @@ -39,4 +40,14 @@ public class TestBooleanQuery extends TestCase { assertEquals(bq1, bq2); } + + public void testException() { + try { + BooleanQuery.setMaxClauseCount(0); + fail(); + } catch (IllegalArgumentException e) { + // okay + } + } + }