Skip to content
Advertisement

java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError

I have a few Scala test classes in a gradle project that work just fine when run individually. But when run through the gradle test task, it fails with the following error in beforeEach of all classes –

java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: xxx.xxx.xxx$.$lessinit$greater$default$20()Ljava/util/List;

The line that it is failing at is creating an instance of a Scala case class which has some default values assigned to all vars. And from the error, it looks like it is failing to create a default java list in that case class. The case class used has multiple lists.

case class SomeClass(
var val1: Boolean = true, 
var val2: java.util.List[java.lang.Long]= new java.util.ArrayList[java.lang.Long],
var val3: java.util.List[String]= new java.util.ArrayList[String]
)

Given that individually the test classes work, I am not sure how is it different when running through test. Any clues that could help me with this? Thanks.

Advertisement

Answer

Seems JDK incompatibility with Scala version.

could you please check the Java & Scala versions mapped accordingly.

from scala website:

JDK version Minimum Scala versions  Recommended Scala versions
17  2.13.6, 2.12.14 (see below) 2.13.6, 2.12.14 (see below)
16  2.13.5, 2.12.14 2.13.6, 2.12.14
13, 14, 15  2.13.2, 2.12.11 2.13.6, 2.12.14
12  2.13.1, 2.12.9  2.13.6, 2.12.14
11  2.13.0, 2.12.4, 2.11.12 2.13.6, 2.12.14, 2.11.12
8   2.13.0, 2.12.0, 2.11.0, 2.10.2  2.13.6, 2.12.14, 2.11.12, 2.10.7
6,7 2.11.0, 2.10.0  2.11.12, 2.10.7

Advertisement