SCALA REPL throwing error at launch - scala

I get the following error when I try to run the SCALA REPL. Note that I have already looked into this post where it talks about downgrading java version.
sg#IN0D196716 C:\Users\sg
$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
sg#IN0D196716 C:\Users\sg
$ scala
Exception in thread "main" java.lang.NoSuchMethodError: scala.util.matching.Regex.unapplySeq(Ljava/lang/CharSequence;)Lscala/Option;
at scala.tools.nsc.settings.ScalaVersion$.apply(ScalaVersion.scala:104)
at scala.tools.nsc.settings.ScalaVersion$.apply(ScalaVersion.scala:114)
at scala.tools.nsc.settings.ScalaVersion$.<init>(ScalaVersion.scala:119)
at scala.tools.nsc.settings.ScalaVersion$.<clinit>(ScalaVersion.scala)
at scala.tools.nsc.settings.ScalaSettings$class.$init$(ScalaSettings.scala:138)
at scala.tools.nsc.settings.MutableSettings.<init>(MutableSettings.scala:20)
at scala.tools.nsc.Settings.<init>(Settings.scala:12)
at scala.tools.nsc.GenericRunnerSettings.<init>(GenericRunnerSettings.scala:11)
at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:18)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:41)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

Sorry, dude, that's my fault.
A few years ago, someone said you should only be able to use a regex to extract from strings (char sequences).
That was such a reasonable request. "Tell me if I try to match a regex to something that isn't even a string!"
Unfortunately, because JVM and maven and ivy, you never know what backwards compatibility issues you'll discover.
As you have discovered.
Scala requires that you build and run with the same "major" version.
Here is a similar issue where "user experience" diverges:
https://issues.scala-lang.org/browse/SI-9380
Additional apologies if you don't prefer the gendered "dude", if it is gendered.

Related

runtime exception using local build of scala compiler: "java.lang.NoSuchMethodError: 'boolean java.lang.StringBuilder.isEmpty()'"

I have a local build of the scala compiler. I get the following exception when I use the three jars for the compiler (compiler/reflect/library) from my build in another Scala application (http://ikojo.in/):
[Thu Aug 25 11:24:22 EDT 2022, Utils] SEVERE: Problem
java.lang.NoSuchMethodError: 'boolean java.lang.StringBuilder.isEmpty()'
at scala.tools.nsc.ast.parser.Scanners$Scanner.checkNoTrailingSeparator(Scanners.scala:1264)
at scala.tools.nsc.ast.parser.Scanners$Scanner.getNumber(Scanners.scala:1302)
at scala.tools.nsc.ast.parser.Scanners$Scanner.fetchToken(Scanners.scala:632)
at scala.tools.nsc.ast.parser.Scanners$Scanner.nextToken(Scanners.scala:422)
...
at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:401)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1519)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1503)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:744)
at scala.tools.nsc.interpreter.IMain$Request.$anonfun$compile$7(IMain.scala:978)
at scala.runtime.java8.JFunction0$mcZ$sp.apply(JFunction0$mcZ$sp.scala:17)
at scala.tools.nsc.interpreter.IMain$.withSuppressedSettings(IMain.scala:1407)
Please note that Java Runtime8 is a caller in this stack trace. The exception is very early in the compiler code itself: during the very first phase of the compiler, the syntax analyzer, out of 23 (or more) phases.
Also note that the code of my local build of the compiler is identical to the official scala release (from: https://github.com/scala/scala/releases/tag/v2.13.6).
I checked the answer to a related question java.lang.NoSuchMethodError: java.lang.String.isEmpty()Z but that doesn't seem to have a good answer, or at least, it is not clear to me.
Does anybody have any hints or any leads on how to debug or resolve this?
In Java versions before 15, java.lang.StringBuilder doesn't have an isEmpty method; Java versions after Java 15 have an isEmpty method.
The Scala compiler's code has a StringBuilderOps implicit class which has an isEmpty method.
Thus, when compiling the Scala compiler with a Java version before 15, the compiler sees (at line 1264) that we're calling the isEmpty method on a StringBuilder. Since there's no isEmpty method on java.lang.StringBuilder, the compiler looks for a class which StringBuilder is implicitly convertible to which has an isEmpty method. If there's exactly one such class (in this case StringBuilderOps), then the compiler says "this isn't an error" and effectively replaces the cbuf.isEmpty call with something like either:
(new StringBufferOps(cbuf)).isEmpty, or
StringBufferOps$.isEmpty(cbuf)
(these are both effectively the same thing: the second one is devirtualized into a static call and might be generated because StringBufferOps extends AnyVal). Note that this does not result in a call to an isEmpty on a StringBufferOps.
If the Java version you're building the compiler with is Java 15 or later, then the compiler sees that there's an isEmpty method on StringBuilder and eventually when it comes time to emit the Java bytecode, it emits the usual code for calling the isEmpty method on a StringBuilder in the JVM.
Because java.lang and similar packages are provided by the Java runtime, they're not included in the jar files. So if you then run the resulting jar files on a pre-Java 15 JVM, there's a reference in the bytecode to a method that doesn't exist and the JVM throws the NoSuchMethodError.
At least for now, I don't believe the Scala compiler officially supports being built with versions of Java that aren't Java 8 or Java 11. If building with a later version, be careful to not use your built compiler with Java versions earlier than what you built with.
Java version which results in the error is the following:
ben#Bulents-MacBook-Pro ~ % java -version
java -version
java version "15.0.1" 2020-10-20
Java(TM) SE Runtime Environment (build 15.0.1+9-18)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
Instead, when I compile the scala compiler with the following, the error is resolved:
ben#Bulents-MacBook-Pro ~ % java -version
java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
I am not sure why or how this works, but it does. I have some guesses, but, they are not very educated. So, if anybody has a deeper insight, please share. Thank you.

Why Can't JVM Find Postgresql JDBC Driver?

I know this question has been asked before, but existing answers do not help.
Existing answers tend to either tell you to put postgresql-.jar in /path/to/db/lib/, which I did; or center around MySQL. I've tried > 5 different answers and nothing is helping.
Here's what I'm running at the Clojure REPL:
(require '[next.jdbc :as jdbc])
(def db {:dbtype "postgres" :dbname "whatever" :user "whoever" :password "yeahright"})
(jdbc/get-connection db)
And I get this error:
Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:702).
No suitable driver found for jdbc:postgresql://127.0.0.1:5432/<db_name>
I know where postgresql-42.2.12.jar is located on my computer, and I used :classpath-add to add that path in project.clj. I have double checked the syntax of the URL and it's correct so far as I can tell.
Java version:
$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
$ lein -version
Leiningen 2.9.1 on Java 10.0.1 Java HotSpot(TM) 64-Bit Server VM
I have the same problem on Ubuntu & Mac. Does anyone know what is going on?
Per the next.jdbc Getting Started guide https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT/doc/getting-started
"In addition, you will need to add dependencies for the JDBC drivers you wish to use for whatever databases you are using."
For lein that means adding the following to your :dependencies vector in project.clj:
[org.postgresql/postgresql "42.2.10"]
(that's the latest version that next.jdbc is tested against at the time of writing, May 23rd, 2020)
Make sure your project.clj contains an entry like this in
[org.postgresql/postgresql "42.2.12"]
in the :dependencies vector.

sbt [error] No valid parser available

I am running:
java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
sbt 0.13.13.
on Windows 10.
When I follow the tutorial to do a println("hello"), I get the error:
[error] No valid parser available.
Do you guys have any idea why that might be and how to resolve?
Thank you very much in advance!
You entered into the sbt shell, which is used to give commands for a project build.
It sounds like you want a Scala console. You can start it by:
sbt console

UnsupportedClassVersionError deploying EJB "HelloWord" in Glasshfish 3

I try to deploy a simple "Hello Word" in my local server GlasshFish 3, but at the deploy the console print this message
[#|2013-01-15T15:00:02.458+0100|SEVERE|glassfish3.1.2|
javax.enterprise.system.tools.admin.org.Exception while deploying the app
[HelloWorldEJB] :UnsupportedClassVersionError: Class ejb_other.PlaceAuctionItemBean
as unsupported major or minor version numbers, which are greater than those found
in the Java Runtime Environment version 1.6.0_27|#]
My JAVA_HOME has java version 1.6.0_27 (it refers to _C:\Program Files\Java\jdk1.6.0_27_), my Eclipse (indigo) project refers to java 1.6.0_27.
I think (i don't know how to verify) that GlasshFish refers to JAVA_HOME.
In my PC (Windows 7) I found 2 directory having java.exe:
C:\Windows\SysWOW64>java -version -->>java version "1.6.0_29"
C:\Windows\System32>java -version -->>java version "1.6.0_27"
I found more discussions about this exception (f.e. this or this ), but I need of something more specific for Eclipse/Glasshfish, because I can't to solve. I see that the JVM is the same for compilation and execution.
Post Scriptim
I add the screenshot about the places where I declare JVM: it's always 1.6.
one:
two:
three:
Where can I see that I compile with java 7 or it runs with another JVM?
ejb_other.PlaceAuctionItemBean was obviously compiled for Java 7 which won't work if you run it in a Java 6 JVM.
Found solution
There's another place where setting the compiler's options:
how do I get eclipse to use a different compiler version for Java?

Using guava in griffon gives Prohibited package exception

I am using Griffon and want to add the guava libraries as a dependency in my project. However, when I do this, even without using 1 class of it, I get the following exception:
Compilation error: BUG! exception in phase 'canonicalization' in source unit
'/home/wdb/myproject/griffon-app/controllers/MyController.groovy' Prohibited
package name: java.util.concurrent
Any idea what might be wrong? This is my java version (on Ubuntu 11.10):
wdb#wdb-laptop:~$ java -version
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) Server VM (build 20.2-b06, mixed mode)
I found this link that talks about using the bootclasspath for a similar problem, but that seems a bit drastic.
regards,
Wim
My wild guess is that our bootclasspath copy of java.util.concurrent.ExecutorService (necessary due to an incompatible change between JDK5 and JDK6) is showing up in your classpath. I don't really know Maven, but I would think that, because we identify the dependency as "provided", this shouldn't be happening.
That's not really an answer, but I hope it's enough to get you or someone else started.
It must be that Griffon does not honor 'provided' scope. I managed to get it working by editing BuilderConfig.groovy to:
compile( 'com.google.guava:guava:10.0.1' ) {
exclude 'guava-bootstrap'
}