Any kind of `.show()` on `java.nio.file.Path` causes a StackOverflowError
See original GitHub issueSimple example:
import io.kotest.assertions.show.show
println(Paths.get("a/b/c").show().value)
fails with the following error:
java.lang.StackOverflowError
at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:2330)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:2329)
at io.kotest.assertions.show.DefaultShowKt.getCollectionSnippet(DefaultShow.kt:45)
at io.kotest.assertions.show.DefaultShowKt.access$getCollectionSnippet(DefaultShow.kt:1)
at io.kotest.assertions.show.DefaultShow.show(DefaultShow.kt:26)
at io.kotest.assertions.show.DefaultShow.show(DefaultShow.kt:27)
at io.kotest.assertions.show.ShowKt.show(Show.kt:25)
at io.kotest.assertions.show.DefaultShowKt.recursiveRepr(DefaultShow.kt:56)
at io.kotest.assertions.show.DefaultShowKt$getCollectionSnippet$1.invoke(DefaultShow.kt:51)
at io.kotest.assertions.show.DefaultShowKt$getCollectionSnippet$1.invoke(DefaultShow.kt)
at kotlin.text.StringsKt__StringBuilderKt.appendElement(StringBuilder.kt:58)
at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:2313)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:2330)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:2329)
at io.kotest.assertions.show.DefaultShowKt.getCollectionSnippet(DefaultShow.kt:45)
...
This is probably caused by the fact that Path
is an Iterable<Path>
.
This problem makes many of the matchers working with Path
s unusable, because they want to print the Path
somehow, which invariably causes a StackOverflowError. For example, something like
val actual: List<Path> = ...
actual.shouldContainExactlyInAnyOrder(
Paths.get("a/b/c"),
Paths.get("d/e/f")
)
also fails with the StackOverflowError
, because it always attempts to show the collections on the left and right sides when it returns MatcherResult
.
Curiously, some other matchers (e.g. shouldContainExactly
) use closures to generate their messages, so they will work in the successful case, but will then result in a stack overflow if their respective assertion fails.
Kotest 4.0.1.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Java NIO file path issue - Stack Overflow
Java NIO file path issue · I wonder why I get the leading character a '/', instead of '\' like in the question....
Read more >How to Fix java.lang.StackOverflowError in Java - Rollbar
StackOverflowError indicates that the application stack is exhausted and is usually caused by deep or infinite recursion.
Read more >The StackOverflowError in Java - Baeldung
In this article, we'll see how this error can occur by looking at a variety of code examples as well as how we...
Read more >How to solve java.lang.StackOverflowError
The java.lang.stackoverflowerror in Java is thrown to indicate that the application's stack was exhausted, due to deep recursion.
Read more >How to resolve the "java.lang.stackoverflowerror" in Java
The java.lang.stackoverflowerror is indicative of serious problems that an application cannot catch (e.g., stack running out of space). It is usually caused ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve investigated this and it’s because Path iterators returned Iterator<Path> so when you call show on each individual element, you get into the infinite loop. Fix applied on master and will be included in 4.0.3
4.0.6 has been released which fixes this.