question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any kind of `.show()` on `java.nio.file.Path` causes a StackOverflowError

See original GitHub issue

Simple 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 Paths 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sksamuelcommented, Apr 14, 2020

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

0reactions
sksamuelcommented, Jun 2, 2020

4.0.6 has been released which fixes this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found