LUCENE-6713: TooComplexToDeterminizeException claims to be serializable but wasn't

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1694218 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-08-05 14:02:25 +00:00
parent 4112979808
commit 2fbe3f747d
3 changed files with 36 additions and 4 deletions

View File

@ -323,6 +323,9 @@ Bug fixes
* LUCENE-6718: JoinUtil.createJoinQuery failed to rewrite queries before
creating 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 ParallelCompositeReader

View File

@ -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;

View File

@ -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-6046
public void testRepeatWithEmptyString() throws Exception {
Automaton a = new RegExp("[^y]*{1,2}").toAutomaton(1000);