Strange Scala Error when Using Scala Reflect - scala

I added a dependency to the scala reflect library version 2.11.8 to one of my existing project such that I could use TypeTag's but strangely I face some error when running. Here is my error:
Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x10a3ab4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10b4ce4e0). One of the two will be used. Which one is undefined.
Exception in thread "main" java.lang.AbstractMethodError: Method com/my/csvparser/CSVParser$.scala$App$_setter_$executionStart_$eq(J)V is abstract
at com.my.csvparser.CSVParser$.scala$App$_setter_$executionStart_$eq(CSVParser.scala)
at scala.App$class.$init$(App.scala:44)
at com.my.csvparser.CSVParser$.<init>(CSVParser.scala:13)
at com.my.csvparser.CSVParser$.<clinit>(CSVParser.scala)
at com.my.csvparser.CSVParser.main(CSVParser.scala)
Did anyone face a similar issue? My Scala version is 2.11.8

Related

jOOQ as a dependency in Scala 3 is broken?

I am trying to use jOOQ as dependency in a Scala 3 codebase:
libraryDependencies ++= Seq("org.jooq" % "jooq" % "3.16.6")
However when I try to do an import from this library -- like import org.jooq.DSLContext -- I get a compilation error.
The easiest way to reproduce this is using ammonite:
cs launch ammonite --scala 3.1.3
Loading...
Welcome to the Ammonite Repl 2.5.4-11-4f5bf2aa (Scala 3.1.3 Java 11.0.15)
# import $ivy.`org.jooq:jooq:3.16.6`, org.jooq.DSLContext
Bad symbolic reference. A signature
refers to ApiStatus/T in package org.jetbrains.annotations which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling the signature.
Caught: java.lang.AssertionError: assertion failed: failure to resolve inner class:
externalName = org.jetbrains.annotations.ApiStatus$Experimental,
outerName = org.jetbrains.annotations.ApiStatus,
innerName = Experimental
owner.fullName = org.jetbrains.annotations.ApiStatus
while parsing /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class) while parsing annotations in /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class)
Caught: java.lang.RuntimeException: bad constant pool index: 0 at pos: 740 while parsing annotations in /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class)
...
This is not the complete error, it gives the same type of error on a bunch of different classes, always related with this annotation org.jetbrains.annotations.ApiStatus.Experimental.
I've reproduced this using Java 11 and 18 (openjdk), using SBT and ammonite, with all versions of Scala 3.
When using Scala 2.13.* everything works correctly, we're using that in production.
Any idea what might be going on here? Any potential clues or possible workarounds?
This is fixed in Scala 3 from version 3.2.0-RC1.
See reddit post in r/scala.

Can't expand macros compiled by previous versions of Scala

I changed my Scala version from 2.10.x to 2.11.8. I am getting some compilation issues. I tried, but still not able to resolve because I am poor in Scala and sbt.
WebService.scala:36: can't expand macros compiled by previous versions of Scala
[error] logger.error(s"WebService.getSiteData(${Id}): Unknown Error, Error Message: $e")
What might be the issue here?
I resolved this issue but it not a single thing, I did couple of things:
First I gone through the error location in WebService.scala.
Then to the corresponding "Logger" class.
I check from which jar that "Logger" class coming.
I found that it referring to some thing else jar than what I am expecting.
That jar is coming from one of my dependent project (modules) so in build.sbt, those dependent jars I excluded that wrong jar which I found.
After I changed the code in WebService.scala, I removed that import for logger and added new import having Logger what I expecting. I did same all the other places in my project.
WebService.scala:36: can't expand macros compiled by previous versions of Scala
[error] logger.error(s"WebService.getSiteData(${Id}): Unknown Error, Error Message: $e")
This is not particular to logger issue. If you are getting "can't expand macros compiled by previous versions of Scala" issue", you have to do same procedure for corresponding to your error (my case logger).
First time, I search online regarding this issue, I found same issue facing lot of people, but different library classes (I face Logger class issue).

New dependency causing java.lang.NoSuchMethodError exception

I'm working on a project that is making use of a Scala ETCD client (https://github.com/nikore/scala-etcd), this has been all fine and good until I added a Scala Fleet client (https://github.com/MonsantoCo/fleet-client) into the mix.
When I compile it is fine but once I run the project it throws the following exception on the lines where the ETCDClient is constructed
Exception in thread "main" java.lang.NoSuchMethodError: spray.json.StandardFormats$class.optionFormat(Lspray/json/StandardFormats;Lspray/json/JsonFormat;)Lspray/json/StandardFormats$OptionFormat;
at net.nikore.etcd.EtcdJsonProtocol$.optionFormat(EtcdJsonProtocol.scala:5)
at net.nikore.etcd.EtcdJsonProtocol$.<init>(EtcdJsonProtocol.scala:18)
at net.nikore.etcd.EtcdJsonProtocol$.<clinit>(EtcdJsonProtocol.scala)
at net.nikore.etcd.EtcdClient.<init>(EtcdClient.scala:76)
at net.nikore.etcd.EtcdClient$.apply(EtcdClient.scala:20)
at au.com.someproject.helpers.SomeProjectService$class.main(SomeProjectService.scala:116)
at au.com.someproject.some_agent.ServiceMain$.main(ServiceMain.scala:17)
at au.com.someproject.some_agent.ServiceMain.main(ServiceMain.scala)
The only thing that I call tell that might be causing this is that the ETCD Client requires spray-json 1.3.1 but the Fleet Client requires spray-json 1.3.2. Having a look at the compiled package, spray-json 1.3.2 is packaged.
What is the cause of this (if I am wrong about the dependencies) and how can I go about resolving this?
EDIT:
Bellow is the code at SomeProjectService.scala:116:
etcdClient = EtcdClient(s"http://${serviceConfiguration.getString("someproject.etcd.host")}:${serviceConfiguration.getString("someproject.etcd.port")}")
And bellow is the code at ServiceMain.scala:17:
object ServiceMain extends SomeProjectService {
ServiceMain is the entry point for the service but the main function is declared in the SomeProjectService trait where the etcdClient is declared

akka-kryo-serialization ClassNotFoundException: scala.Enumeration$Val

Sometimes when updating a dependency version for my project, when I would run the project I would get the following error:
ERROR 09:31:34:241 apply$mcV$sp - Class could not be loaded and/or registered: scala.Enumeration$Val
ERROR 09:31:34:247 apply$mcV$sp - exception caught during akka-kryo-serialization startup: java.lang.ClassNotFoundException: scala.Enumeration$Val
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
I usually got lucky and was able to fix this by tweaking the versions of my dependencies.
Until I updated my akka version from 2.3.6 to 2.3.12, specifically akka-contrib which contains akka-cluster, akka-remote and akka-peristance.
Turns out that the problem was actually occurring during the transition between akka 2.3.8 and 2.3.9. Looking at the change log, I found that between these two versions the Scala version was upgraded from 2.11.4 to 2.11.5.
My project was building on scala 2.11.4. Upgrading to 2.11.5 fixed the problem.
I couldn't find any help online for this, and lost a couple days trying to figure this out. I'm hoping that this will help someone else out.

NoSuchMethodError when initialising actors in Scala 2.8

I recently downgraded to Scala 2.8, and now whenever I try to initialise an actor, I get the following error message:
java.lang.NoSuchMethodError: scala.actors.ReactorCanReply$class.$init$(Lscala/actors/ReactorCanReply;)V
Apparently this guy had the same problem, but no solution was found. Has anyone else encountered this and solved it?
I thought that maybe there was some sonfusion going on in the background between Scala 2.8 and 2.9 files, so I've tried uninstalling and reinstalling both Scala and Eclipse, deleting all my binaries and rebuilding, and even creating a new Eclipse project and copying my source files in, but the problem persists.
My stack trace:
Exception in thread "main" java.lang.NoSuchMethodError: scala.actors.ReactorCanReply$class.$init$(Lscala/actors/ReactorCanReply;)V
at uk.mike.blackjack.PlayerReceiver.<init>(PlayerReceiver.scala:11)
at uk.mike.blackjack.Blackjack$.main(Blackjack.scala:141)
at uk.mike.blackjack.Blackjack.main(Blackjack.scala)
The Java bytecode compiled from Scala is not backward-compatible. You must recompile all your scala file and their dependencies when you upgrade to any new Scala version before Scala 2.10 releases.
BTW: Scala 2.10 promises to keep backward-compatible between all 2.10.x versions in the future.