Skip to content

Java 9+: staging classpath handling #9500

Closed
@liufengyun

Description

@liufengyun

When run the test set with JDK 11, we get two errors:

(1) Failure in project/scripts/bootstrapCmdTests

+ ./project/scripts/sbt ';dotty-compiler-bootstrapped/dotc -with-compiler tests/run-staging/quote-run.scala; dotty-compiler-bootstrapped/dotr -with-compiler Test'
Exception in thread "main" dotty.tools.dotc.MissingCoreLibraryException: Could not find package scalaShadowing from compiler core libraries.
Make sure the compiler core libraries are on the classpath.

  at dotty.tools.dotc.core.Denotations$.select$1(Denotations.scala:1222)
  at dotty.tools.dotc.core.Denotations$.recurSimple$1(Denotations.scala:1250)
  at dotty.tools.dotc.core.Denotations$.recur$1(Denotations.scala:1252)
  at dotty.tools.dotc.core.Denotations$.staticRef(Denotations.scala:1254)
  at dotty.tools.dotc.core.Symbols$.requiredPackage(Symbols.scala:890)
  at dotty.tools.dotc.core.Definitions.ScalaShadowingPackage(Definitions.scala:255)
  at dotty.tools.dotc.core.Definitions.init(Definitions.scala:1496)
  at dotty.tools.dotc.core.Contexts$ContextBase.initialize(Contexts.scala:790)
  at dotty.tools.dotc.core.Contexts$Context.initialize(Contexts.scala:554)
  at dotty.tools.dotc.Run.rootContext(Run.scala:64)
  at dotty.tools.dotc.Run.<init>(Run.scala:84)
  at scala.quoted.staging.QuoteCompiler$ExprRun.<init>(QuoteCompiler.scala:102)
  at scala.quoted.staging.QuoteCompiler.newRun(QuoteCompiler.scala:45)
  at scala.quoted.staging.QuoteDriver.run(QuoteDriver.scala:40)
  at scala.quoted.staging.Toolbox$$anon$1.run(Toolbox.scala:36)
  at scala.quoted.staging.package$.run(staging.scala:19)
  at Test$.main(quote-run.scala:12)
  at Test.main(quote-run.scala)

(2) tests/run-staging/i6992

-- Error: tests/run-staging/i6992/Test_2.scala:7:16 -------------------------------
7 |    println(mcr {foo})
  |            ^^^^^^^^^
  | Exception occurred while executing macro expansion.
  | dotty.tools.dotc.MissingCoreLibraryException: Could not find package scalaShadowing from compiler core libraries.
  | Make sure the compiler core libraries are on the classpath.

The errors originate from a change of class loading in Java 9 (due to the module system):

https://stackoverflow.com/questions/46694600/java-9-compatability-issue-with-classloader-getsystemclassloader#comment80337394_46694600

In Java 9, the classloader is no longer a URLClassLoader, which breaks the following code:

https://github.com/lampepfl/dotty/blob/8eea8d8bba1da247553161e981d6d277eb375a4b/compiler/src/dotty/tools/dotc/util/ClasspathFromClassloader.scala#L10-L42

There exists a hack to achieve similar results in Java 9+

https://stackoverflow.com/questions/46519092/how-to-get-all-jars-loaded-by-a-java-application-in-java9

Related PR: #9181

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions