Object java.lang.Object in compiler mirror not found

I have this error while trying to instantiate an object of type Global in Scala 2.12.19 with JDK 17.

object java.lang.Object in compiler mirror not found

It used to work with Scala 2.12.6 and JDK 8.

I tried to solve the error by adding settings but that didn’t help :

compilerSettings.processArgumentString(“–release:17 --target:17”)

The full stack trace is :

scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.
at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:24)
at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:25)
at scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$5(Mirrors.scala:61)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:51)
at scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:51)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:301)
at scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:301)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1511)
at scala.tools.nsc.Global$Run.(Global.scala:1225)
at scala.tools.nsc.interactive.Global$TyperRun.(Global.scala:1323)
at scala.tools.nsc.interactive.Global.newTyperRun(Global.scala:1346)
at scala.tools.nsc.interactive.Global.(Global.scala:294)
at org.scalaide.core.internal.compiler.ScalaPresentationCompiler.(ScalaPresentationCompiler.scala:55)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy.liftedTree1$1(PresentationCompilerProxy.scala:156)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy.create(PresentationCompilerProxy.scala:153)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy.initialize(PresentationCompilerProxy.scala:118)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy.obtainPc$1(PresentationCompilerProxy.scala:80)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy.internal(PresentationCompilerProxy.scala:100)
at org.scalaide.core.internal.jdt.model.ScalaCompilationUnit.addToIndexer(ScalaCompilationUnit.scala:158)
at org.scalaide.core.internal.jdt.model.ScalaCompilationUnit.addToIndexer$(ScalaCompilationUnit.scala:156)
at org.scalaide.core.internal.jdt.model.ScalaSourceFile.addToIndexer(ScalaSourceFile.scala:70)
at org.scalaide.core.internal.jdt.search.ScalaSourceIndexer.$anonfun$indexDocument$2(ScalaSourceIndexer.scala:16)
at org.scalaide.core.internal.jdt.search.ScalaSourceIndexer.$anonfun$indexDocument$2$adapted(ScalaSourceIndexer.scala:16)
at scala.Option.map(Option.scala:230)
at org.scalaide.core.internal.jdt.search.ScalaSourceIndexer.indexDocument(ScalaSourceIndexer.scala:16)
at scala.tools.eclipse.contribution.weaving.jdt.indexerprovider.IndexerProviderAspect.ajc$around$scala_tools_eclipse_contribution_weaving_jdt_indexerprovider_IndexerProviderAspect$1$16276a3c(IndexerProviderAspect.aj:30)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.indexDocument(JavaSearchParticipant.java:77)
at org.eclipse.jdt.internal.core.search.indexing.IndexManager.indexDocument(IndexManager.java:674)
at org.eclipse.jdt.internal.core.search.indexing.IndexManager$2.execute(IndexManager.java:1286)
at org.eclipse.jdt.internal.core.search.processing.JobManager.indexerLoop(JobManager.java:542)
at java.base/java.lang.Thread.run(Thread.java:833)

The instantiation of the ScalaPresentationCompiler which extends Global is here:

This is only a guess, but I wonder if -usejavacp would help. (I wouldn’t expect -release or -target to help.)

Just tried it. Unfortunately, it didn’t work for me.

I tried like this:

compilerSettings.processArgumentString("-usejavacp")

and like this:

compilerSettings.usejavacp.value = true

The java command uses osgi :

C:\Users\nicol\Downloads\jdk-17.0.4_windows-x64_bin\jdk-17.0.4\bin\java.exe -Dosgi.noShutdown=false -Dosgi.os=win32 -Dosgi.ws=win32 -Dosgi.arch=x86_64 --add-opens java.base/java.lang=ALL-UNNAMED -Xmx2048m -Dsdtcore.headless -Dsdtcore.notimeouts -DretryFlakyTests=true -XX:+UnlockDiagnosticVMOptions -Dosgi.classloader.lock=classname -Dosgi.clean=true -Daj.weaving.verbose=true -Dorg.aspectj.osgi.verbose=true -Dorg.aspectj.weaver.showWeaveInfo=true -jar C:\Users\nicol.m2\repository\p2\osgi\bundle\org.eclipse.equinox.launcher\1.6.700.v20240213-1244\org.eclipse.equinox.launcher-1.6.700.v20240213-1244.jar -data C:\Users\nicol\git\scala-ide\org.scala-ide.sdt.core.tests\target\work\data -install C:\Users\nicol\git\scala-ide\org.scala-ide.sdt.core.tests\target\work -configuration C:\Users\nicol\git\scala-ide\org.scala-ide.sdt.core.tests\target\work\configuration -application org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties C:\Users\nicol\git\scala-ide\org.scala-ide.sdt.core.tests\target\surefire.properties

I’d like to understand what is the real meaning of this error. Object is of course available. But how do I make Object available in compiler mirror ?
Also I tried to activate some debug information but it seemed to have no effect:

compilerSettings.debug.value = true
StatisticsStatics.enableDebugAndDeoptimize()

The error means that the compiler classpath is incomplete. You should check the classpath argument you’re passing to the compiler and make sure it includes a JDK and a scala library (probably you’d need more, like scala-reflect as well). This area is fairly involved, but if you grep through the sources you should find where this is picked up from. Note that you may run Eclipse (and the Scala compiler) with one JDK, but perfectly well pass another one to the compiler for compiling sources.

usejavacp is a shortcut that tells the compiler to look in the running JVM and pick whatever is in there as the JDK, but you should probably avoid that in your use case.

It makes sense. I tried to pass the compile classpath as a vm property for the tests. Now I don’t have any errors anymore but the tests are neither succeeding nor failing, which is strange. In the end, the test job says it will shutdown due to inactivity, but it does not terminate.

Any idea which options I need to activate to investigate ?