Apache Lucene open-source search software
LUCENE-7576: AutomatonTermsEnum ctor should also insist on a NORMAL CompiledAutomaton in
Mike McCandlessebb5c7e6768c
diff --git a/lucene/core/src/java/org/apache/lucene/index/AutomatonTermsEnum.java b/lucene/core/src/java/org/apache/lucene/index/AutomatonTermsEnum.javaindex 8aa10ece7f5..411a8107f1a 100644--- a/lucene/core/src/java/org/apache/lucene/index/AutomatonTermsEnum.java+++ b/lucene/core/src/java/org/apache/lucene/index/AutomatonTermsEnum.java@@ -76,6 +76,9 @@ public class AutomatonTermsEnum extends FilteredTermsEnum {*/public AutomatonTermsEnum(TermsEnum tenum, CompiledAutomaton compiled) {super(tenum);+ if (compiled.type != CompiledAutomaton.AUTOMATON_TYPE.NORMAL) {+ throw new IllegalArgumentException("please use CompiledAutomaton.getTermsEnum instead");+ }this.finite = compiled.finite;this.runAutomaton = compiled.runAutomaton;assert this.runAutomaton != null;diff --git a/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.java b/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.javaindex a388d42ae30..d2df59ff4fd 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestTermsEnum.java@@ -1016,4 +1016,12 @@ public class TestTermsEnum extends LuceneTestCase {w.close();d.close();}++ // LUCENE-7576+ public void testInvalidAutomatonTermsEnum() throws Exception {+ expectThrows(IllegalArgumentException.class,+ () -> {+ new AutomatonTermsEnum(TermsEnum.EMPTY, new CompiledAutomaton(Automata.makeString("foo")));+ });+ }}