Apache Solr open-source search software
LUCENE-6713: TooComplexToDeterminizeException claims to be serializable but wasn't
Michael McCandless2fbe3f747d28
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 790b49ca15b..55c8adea4e6 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -323,6 +323,9 @@ Bug fixes* LUCENE-6718: JoinUtil.createJoinQuery failed to rewrite queries beforecreating a Weight. (Adrien Grand)+* LUCENE-6713: TooComplexToDeterminizeException claims to be serializable+ but wasn't (Simon Willnauer, Mike McCandless)+Changes in Runtime Behavior* LUCENE-6501: The subreader structure in ParallelCompositeReaderdiff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/TooComplexToDeterminizeException.java b/lucene/core/src/java/org/apache/lucene/util/automaton/TooComplexToDeterminizeException.javaindex ca3d18dc9f2..5fb4639de5e 100644--- a/lucene/core/src/java/org/apache/lucene/util/automaton/TooComplexToDeterminizeException.java+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/TooComplexToDeterminizeException.java@@ -22,9 +22,9 @@ package org.apache.lucene.util.automaton;* has too many states.*/public class TooComplexToDeterminizeException extends RuntimeException {- private final Automaton automaton;- private final RegExp regExp;- private final int maxDeterminizedStates;+ private transient final Automaton automaton;+ private transient final RegExp regExp;+ private transient final int maxDeterminizedStates;/** Use this constructor when the RegExp failed to convert to an automaton. */public TooComplexToDeterminizeException(RegExp regExp, TooComplexToDeterminizeException cause) {@@ -37,7 +37,7 @@ public class TooComplexToDeterminizeException extends RuntimeException {/** Use this constructor when the automaton failed to determinize. */public TooComplexToDeterminizeException(Automaton automaton, int maxDeterminizedStates) {- super("Determinizing automaton would result in more than " + maxDeterminizedStates + " states.");+ super("Determinizing automaton with " + automaton.getNumStates() + " states and " + automaton.getNumTransitions() + " transitions would result in more than " + maxDeterminizedStates + " states.");this.automaton = automaton;this.regExp = null;this.maxDeterminizedStates = maxDeterminizedStates;diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.javaindex 63bd074b72a..331bb595b01 100644--- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java+++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestRegExp.java@@ -19,6 +19,13 @@ package org.apache.lucene.util.automaton;import org.apache.lucene.util.LuceneTestCase;+import java.io.ByteArrayInputStream;+import java.io.ByteArrayOutputStream;+import java.io.ObjectInput;+import java.io.ObjectInputStream;+import java.io.ObjectOutput;+import java.io.ObjectOutputStream;+public class TestRegExp extends LuceneTestCase {/**@@ -49,6 +56,28 @@ public class TestRegExp extends LuceneTestCase {}}+ // LUCENE-6713+ public void testSerializeTooManyStatesToDeterminizeExc() throws Exception {+ // LUCENE-6046+ String source = "[ac]*a[ac]{50,200}";+ try {+ new RegExp(source).toAutomaton();+ fail();+ } catch (TooComplexToDeterminizeException e) {+ assert(e.getMessage().contains(source));++ ByteArrayOutputStream bos = new ByteArrayOutputStream();+ ObjectOutput out = new ObjectOutputStream(bos);+ out.writeObject(e);+ byte[] bytes = bos.toByteArray();++ ByteArrayInputStream bis = new ByteArrayInputStream(bytes);+ ObjectInput in = new ObjectInputStream(bis);+ TooComplexToDeterminizeException e2 = (TooComplexToDeterminizeException) in.readObject();+ assertNotNull(e2.getMessage());+ }+ }+// LUCENE-6046public void testRepeatWithEmptyString() throws Exception {Automaton a = new RegExp("[^y]*{1,2}").toAutomaton(1000);