Prevent infinite recursion in case of circular suppressed chains

#KT-37603
This commit is contained in:
Ilya Gorbunov
2020-03-19 05:46:47 +03:00
parent 552bcdb31b
commit 5fe8071d71
2 changed files with 41 additions and 6 deletions
+26
View File
@@ -127,6 +127,32 @@ class ExceptionTest {
assertInTrace(causeSuppressed)
}
// fail(topLevelTrace) // to dump the entire trace
}
@Test
fun circularSuppressedDetailedTrace() {
if (!supportsSuppressedExceptions) return
// Testing an exception of the following structure
// e1
// -- suppressed: e3
// -- suppressed: e1
// Caused by: e2
// -- suppressed: e1
// Caused by: e3
val e3 = Exception("e3")
val e2 = Error("e2", e3)
val e1 = RuntimeException("e1", e2)
e1.addSuppressed(e3)
e3.addSuppressed(e1)
e2.addSuppressed(e1)
val topLevelTrace = e1.toStringWithTrace()
assertEquals(3, Regex.fromLiteral(e1.toString()).findAll(topLevelTrace).count(), topLevelTrace)
assertEquals(1, Regex.fromLiteral(e2.toString()).findAll(topLevelTrace).count(), topLevelTrace)
assertEquals(2, Regex.fromLiteral(e3.toString()).findAll(topLevelTrace).count(), topLevelTrace)
// fail(topLevelTrace) // to dump the entire trace
}