Incorrect serialVersionUID on Scala class
While testing an application relying on Java serialization between several nodes in a cluster to operate, I stumbled on an exception:
Caused by: java.io.InvalidClassException: java.class.XXX; local class incompatible: stream classdesc serialVersionUID = 5893177478437626661, local class serialVersionUID = -2099619866804728723
at java.base/java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.base/java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
Of course, I eliminated all the most obvious reasons for the exception: all libraries were on the same versions on my test application as on all the other nodes of the cluster, same Java version, same env, and so on.
After hours of debugging, the exception went away after removing JaCoCo gradle integration, which is a tool relying on ASM. I could see ASM has a "SerialVersionUIDAdder" class that can add serialVersionUID to classes that don't have one, which is my case.
I believe ASM is generating a different serialVersionUid as the one generated by the JVM.
The offending class (or rather, trait, as this is originally Scala code) is the StructDef
trait that can be found here: https://github.com/datastax/spark-cassandra-connector/blob/v3.2.0/driver/src/main/scala/com/datastax/spark/connector/cql/Schema.scala#L34
Tested with latest ASM version 9.4. Tested with different implementations of Java 11 SDK (corretto, graalvm). I'm going to disable code coverage utilities as they don't make sense in my case, but I post this issue anyway for people who might face it.