diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/Automata.java b/lucene/core/src/java/org/apache/lucene/util/automaton/Automata.java index b33edda3500..2dba6ed483c 100644 --- a/lucene/core/src/java/org/apache/lucene/util/automaton/Automata.java +++ b/lucene/core/src/java/org/apache/lucene/util/automaton/Automata.java @@ -233,25 +233,27 @@ final public class Automata { throw new IllegalArgumentException("maxInclusive must be true when max is null (open ended)"); } - if (min != null && min.length == 0 && minInclusive == true) { - // Silly empty string corner case: - min = null; - } - if (min == null) { - if (max == null) { - // Accepts all terms: - return makeAnyBinary(); - } min = new BytesRef(); minInclusive = true; } + + // Empty string corner case: + if (max != null && maxInclusive == false && max.length == 1 && max.bytes[max.offset] == 0) { + max = new BytesRef(); + maxInclusive = true; + } + int cmp; if (max != null) { cmp = min.compareTo(max); } else { cmp = -1; + if (min.length == 0 && minInclusive) { + return makeAnyBinary(); + } } + if (cmp == 0) { if (minInclusive == false || maxInclusive == false) { return makeEmpty(); diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java index ccc99211a57..a43905a165c 100644 --- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java +++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestAutomaton.java @@ -1125,6 +1125,8 @@ public class TestAutomaton extends LuceneTestCase { System.out.println("Original was not minimal:"); System.out.println("Original:\n" + a.toDot()); System.out.println("Minimized:\n" + minA.toDot()); + System.out.println("minTerm=" + minTerm + " minInclusive=" + minInclusive); + System.out.println("maxTerm=" + maxTerm + " maxInclusive=" + maxInclusive); fail("auotmaton was not minimal"); } @@ -1233,7 +1235,6 @@ public class TestAutomaton extends LuceneTestCase { public void testAcceptAllEmptyStringMin() throws Exception { Automaton a = Automata.makeBinaryInterval(new BytesRef(), true, null, true); - System.out.println("HERE: " + a.toDot()); assertTrue(Operations.sameLanguage(Automata.makeAnyBinary(), a)); }