kotlinkotlin-stdlib

Kotlin code failing in runtime with java.lang.NoSuchMethodError: 'java.util.List java.util.stream.Stream.toList()'


I have a code like stream.toList(), the file contains import kotlin.streams.toList, compilation works w/o issues, but it blows in runtime with the java.lang.NoSuchMethodError: 'java.util.List java.util.stream.Stream.toList()'.

It seems like some package kotlin.streams clash, but I haven't found anything it should collide with.

BTW, it's being run in Docker.


Solution

  • Are you sure that you are importing kotlin.streams.toList? Check all of your source files for any usage of Stream.toList() that doesn't have import kotlin.stream.toList at the top of the file. Your stack trace should also tell you which file that is (but you may have more than one such file).

    The problem is that Java itself has a Stream.toList() method, but this was only introduced in Java 16. From the error message, it looks like your code is using that. But if your Docker container has a version of Java earlier than 16, that method won't be there.

    Make sure to import the Kotlin extension function Stream.toList(), which will exist under all JVM targets.