Scala. NoSuchMethodException when instantiating trait - scala

After refactoring some projects, I I got the following Exception when calling a scala class that implements a trait from a Spring Boot application
8/06/22 13:32:26 ERROR SpringApplication: Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MLController' defined in URL [jar:file:/home/xxxx/environment/spark-2.2.1-bin-hadoop2.7/./xxxx/ikodaanalysis-mlserver-0.1.0.jar!/xxx/mlserver/MLController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [xxx.mlserver.MLController]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: ikoda.utilobjects.SparkConfProviderWithStreaming.$init$(Lxxx/utilobjects/SparkConfProviderWithStreaming;)V
I checked the dependencies and everything appeared to be present in the jar.
So why was I getting the Exception?

I found the answer here. I felt it was probably a fairly common issue and worth reporting on SO.
I assume it's down to Java 8 and Scala 2.12 expecting to find the "init" method in the ScalaDsl.class file (new style Traits as interfaces) rather than in ScalaDsl$class.class file (old style Traits as interface and supporting class).
......
I think the Scala 2.12 package needs to be compiled (not just run)
under Java 8 to avoid this problem.

Related

Strange Scala Error when Using Scala Reflect

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

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

BeanCreationException Vaadin

I'm trying to integrate Spring Boot Vaadin (https://github.com/peholmst/vaadin4spring) with Vaadin's Dashboard Demo Code (https://github.com/vaadin/dashboard-demo). The only thing modification I made was add the annotation "#VaadinUI" in the DashboardUI class. I checked in my code using the branch "integrate-vaadin-dashboard-demo-project".
I get the error message:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider.
I'm not really sure what the message means. Can somebody explain it and come up with a resolution to the error message?
Gist Error Output:
https://gist.github.com/anonymous/43d602c1105e00d4d7d6
Clone Url:
https://github.com/caritos/pangolin.git
Branch:
integrate-vaadin-dashboard-demo-project
You pack javax validation api 1.0 in your jar. This is the version the GWT compiler needs (when you build a widgetset). But spring-boot depends on version 1.1. Usually the problem is the other way around...

Spring-data-neo4j and compatibility with Scala

I suspect that Spring-data-neo4j 2.1.0-BUILD-SNAPSHOT isn't really compatible with some versions of Scala.
I use scala 2.10.0 and using a Play! web application based on scala 2.10.0 too.
While running a test involving a Neo4jTemplate autowired by Spring, I obtain this error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'mappingInfrastructure' defined in class
org.springframework.data.neo4j.config.Neo4jConfiguration: Invocation of init method failed;
nested exception is java.lang.NoSuchMethodError:
scala.collection.JavaConverters$.mapAsScalaMapConverter(Ljava/util/Map;)Lscala/collection/JavaConverters$AsScala
Does a fix exist or would be scheduled?

eclipse Platform.getOS/getV throwing exception

Eclipse Platform.getOS is throwing null Pointer Exception.
Even any kind of operation with Platform is throing exception.
Exception in thread "main"
java.lang.NullPointerException at
org.eclipse.core.internal.runtime.InternalPlatform.getOS(InternalPlatform.java:454)
at
org.eclipse.core.runtime.Platform.getOS(Platform.java:1185)
at Test.main(Test.java:6)
Are you running your classes on top of OSGi or just accessing the Platform class within a plain java application?