Skip to content

Java 9+: staging classpath handling #9500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
liufengyun opened this issue Aug 5, 2020 · 1 comment · Fixed by #9506
Closed

Java 9+: staging classpath handling #9500

liufengyun opened this issue Aug 5, 2020 · 1 comment · Fixed by #9506

Comments

@liufengyun
Copy link
Contributor

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

@smarter
Copy link
Member

smarter commented Aug 5, 2020

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

If all that's missing are the jars from the system classloader, we should be able to get them using System.getProperty("java.class.path")

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 6, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 6, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 6, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants