Skip to content

Commit

Permalink
Add test for LUCENE-10181
Browse files Browse the repository at this point in the history
  • Loading branch information
cfournie committed Apr 27, 2023
1 parent 1fa2be9 commit 909e98f
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.lucene.util.graph;

import java.util.ArrayList;
import java.util.Iterator;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
Expand Down Expand Up @@ -660,4 +661,27 @@ public void testMultipleSidePathsWithGaps() throws Exception {
it.next(), new String[] {"king", "alfred", "saxons", "ruled"}, new int[] {1, 1, 3, 1});
assertFalse(it.hasNext());
}

public void testLongTokenStreamStackOverflowError() throws Exception {
ArrayList<Token> tokens =
new ArrayList<Token>() {
{
add(token("turbo", 1, 1));
add(token("fast", 0, 2));
add(token("charged", 1, 1));
add(token("wi", 1, 1));
add(token("wifi", 0, 2));
add(token("fi", 1, 1));
}
};

// Add in too many tokens to get a high depth graph
for (int i = 0; i < 1024 * 10; i++) {
tokens.add(token("network", 1, 1));
}

TokenStream ts = new CannedTokenStream(tokens.toArray(new Token[0]));
GraphTokenStreamFiniteStrings graph = new GraphTokenStreamFiniteStrings(ts);
graph.articulationPoints(); // This will cause a java.lang.StackOverflowError
}
}

0 comments on commit 909e98f

Please sign in to comment.