diff --git a/lucene/core/src/java/org/apache/lucene/util/graph/GraphTokenStreamFiniteStrings.java b/lucene/core/src/java/org/apache/lucene/util/graph/GraphTokenStreamFiniteStrings.java index 048cf0ab00c9..4a00119cc30b 100644 --- a/lucene/core/src/java/org/apache/lucene/util/graph/GraphTokenStreamFiniteStrings.java +++ b/lucene/core/src/java/org/apache/lucene/util/graph/GraphTokenStreamFiniteStrings.java @@ -275,7 +275,7 @@ private static void articulationPointsRecurse( if (d < MAX_RECURSION_LEVEL) { articulationPointsRecurse(a, t.dest, d + 1, depth, low, parent, visited, points); } else { - continue; + throw new IllegalArgumentException("Exceeded maximum recursion level during graph analysis"); } childCount++; if (low[t.dest] >= depth[state]) { diff --git a/lucene/core/src/test/org/apache/lucene/util/graph/TestGraphTokenStreamFiniteStrings.java b/lucene/core/src/test/org/apache/lucene/util/graph/TestGraphTokenStreamFiniteStrings.java index 56fadc901445..2cbf41ea605e 100644 --- a/lucene/core/src/test/org/apache/lucene/util/graph/TestGraphTokenStreamFiniteStrings.java +++ b/lucene/core/src/test/org/apache/lucene/util/graph/TestGraphTokenStreamFiniteStrings.java @@ -684,32 +684,6 @@ public void testLongTokenStreamStackOverflowError() throws Exception { TokenStream ts = new CannedTokenStream(tokens.toArray(new Token[0])); GraphTokenStreamFiniteStrings graph = new GraphTokenStreamFiniteStrings(ts); - Iterator it = graph.getFiniteStrings(); - assertTrue(it.hasNext()); - it.next(); - assertTrue(it.hasNext()); - it.next(); - assertFalse(it.hasNext()); - - int[] points = graph.articulationPoints(); // This will cause a java.lang.StackOverflowError - assertEquals(points[0], 1); - assertEquals(points[1], 3); - assertEquals(points.length, MAX_RECURSION_LEVEL - 2); - - assertFalse(graph.hasSidePath(0)); - it = graph.getFiniteStrings(0, 1); - assertTrue(it.hasNext()); - assertTokenStream(it.next(), new String[] {"fast"}, new int[] {1}); - assertFalse(it.hasNext()); - Term[] terms = graph.getTerms("field", 0); - assertArrayEquals(terms, new Term[] {new Term("field", "fast")}); - - assertTrue(graph.hasSidePath(1)); - it = graph.getFiniteStrings(1, 3); - assertTrue(it.hasNext()); - assertTokenStream(it.next(), new String[] {"wi", "fi"}, new int[] {1, 1}); - assertTrue(it.hasNext()); - assertTokenStream(it.next(), new String[] {"wifi"}, new int[] {1}); - assertFalse(it.hasNext()); + assertThrows(IllegalArgumentException.class, () -> graph.articulationPoints()); } }