Give this class
final case class Score(val value: BigInt, val random: Long = randomLong)
extends Comparable[Score] {
override def compareTo(that: Score): Int = {
if (this.value < that.value) -1
else if (this.value > that.value) 1
else if (this.random < that.random) -1
else if (this.random > that.random) 1
else 0
}
override def equals(obj: _root_.scala.Any): Boolean = {
val that = obj.asInstanceOf[Score] // (package.scala:48)
this.value == that.value && this.random == that.random
}
}
Everything compiles correctly. When I used to run my unit tests it worked fine a few days ago. I have not changed this code for weeks, and all my tests worked fine, in particular the tests that exercised this code. But now when I run my unit tests I get
class java.lang.Integer cannot be cast to class net.kolotyluk.leaderboard.scorekeeping.package$Score (java.lang.Integer is in module java.base of loader 'bootstrap'; net.kolotyluk.leaderboard.scorekeeping.package$Score is in unnamed module of loader 'app')
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class net.kolotyluk.leaderboard.scorekeeping.package$Score (java.lang.Integer is in module java.base of loader 'bootstrap'; net.kolotyluk.leaderboard.scorekeeping.package$Score is in unnamed module of loader 'app')
at net.kolotyluk.leaderboard.scorekeeping.package$Score.equals(package.scala:48)
Obviously something has changed, but I am not sure what.
The problem seems to be related to the Java 9 modules feature: How many unnamed modules are created in Java 9?
> java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
My JDK has not changed. Possibly some of the versions of my maven dependencies have changed. While the code for my Score class has not changed, I have been moving things around in the package hierarchy.
Does anyone have any ideas on what else the problem may be, or other things I should investigate?