-
Notifications
You must be signed in to change notification settings - Fork 118
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
Keep track of java dependencies in JDK versions > 8 #609
Comments
This is true for now, but in the future the Scala compiler will support using Java and Scala libraries defined in the modulepath instead of the classpath, and everything in the modulepath will be in the jrt filesystem and represented by scalac using PlainNioFile. What is needed is a way to get the path of the module from a PlainNioFile, I haven't checked but it's possible PlainNioFile#container already does the right thing. |
Yes, good point, I was only referring to this as a temporary solution for our current versions of Scala. We'll probably need to rethink this for zinc support in 2.13 and Scala 3. |
@retronym What's the proper way to go from a PlainNioFile to the corresponding file in the real file system if one exists? Is calling .container good enough ? |
Looks like we don't have a good story there. Using https://github.com/retronym/scala/tree/review/jdk11
We should change scalac to:
Added these to scala/scala#7218 |
``` $ ./build/quick/bin/scala Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile.asInstanceOf[scala.reflect.io.PlainNioFile].underlyingSource path: Option[scala.reflect.io.AbstractFile] = Some(/Users/jz/.jabba/jdk/openjdk@1.11.0/Contents/Home/jmods/java.base.jmod) scala> .get.exists res0: Boolean = true ``` ``` $ ./build/quick/bin/scala -release 8 Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile.asInstanceOf[scala.reflect.io.PlainNioFile] path: scala.reflect.io.PlainNioFile = /8/java/lang/String.sig scala> .exists res2: Boolean = true ``` References sbt/zinc#609
``` $ ./build/quick/bin/scala Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile path: scala.reflect.io.AbstractFile = /modules/java.base/java/lang/String.class scala> .underlyingSource res0: Option[scala.reflect.io.AbstractFile] = Some(/Users/jz/.jabba/jdk/openjdk@1.11.0/Contents/Home/jmods/java.base.jmod) scala> .get.exists res1: Boolean = true res0: Boolean = true ``` ``` $ ./build/quick/bin/scala -release 8 Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile path: scala.reflect.io.AbstractFile = /8/java/lang/String.sig scala> .underlyingSource res3: Option[scala.reflect.io.AbstractFile] = Some(/Users/jz/.jabba/jdk/openjdk@1.11.0/Contents/Home/lib/ct.sym) scala> .get.exists res4: Boolean = true ``` References sbt/zinc#609
``` $ ./build/quick/bin/scala Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile path: scala.reflect.io.AbstractFile = /modules/java.base/java/lang/String.class scala> .underlyingSource res0: Option[scala.reflect.io.AbstractFile] = Some(/Users/jz/.jabba/jdk/openjdk@1.11.0/Contents/Home/jmods/java.base.jmod) scala> .get.exists res1: Boolean = true res0: Boolean = true ``` ``` $ ./build/quick/bin/scala -release 8 Welcome to Scala 2.13.0-20190221-140355-c0a7682 (OpenJDK 64-Bit Server VM, Java 11). Type in expressions for evaluation. Or try :help. scala> :power scala> val path = symbolOf[java.lang.String].associatedFile path: scala.reflect.io.AbstractFile = /8/java/lang/String.sig scala> .underlyingSource res3: Option[scala.reflect.io.AbstractFile] = Some(/Users/jz/.jabba/jdk/openjdk@1.11.0/Contents/Home/lib/ct.sym) scala> .get.exists res4: Boolean = true ``` References sbt/zinc#609
We have a similar issue where zinc is throwing exceptions when analyzing dependencies. We have a use-case where we use sbt/zinc to compile a mixed Scala and Java project that depends on a Java module (GraalVM Truffle API) which is closed by default (to prevent insecure introspection) but it ships with an alternative open version that is to be used for compilation. zinc/internal/zinc-classfile/src/main/scala/sbt/internal/inc/classfile/JavaAnalyze.scala Line 50 in 0fcb33d
IllegallAccessError . As this fail happens after the load call (when manipulating the loaded class to find its inheritance dependencies) and it is not expected, the exception aborts compilation.
Our current fix to it is to override the module seen by the JVM running sbt and zinc by adding Any chance that a future version will have some more sophisticated support of overriding the modules or maybe just overriding these security exceptions altogether? If javac succeeded, then compilation should not be terminated because the dependency analysis process is unable to read some class files due to insufficient permissions. Intuitively it seems that the compiler should have all the permissions enabled by default. |
In a JDK version greater than 8, zinc will not correctly register dependencies on Java code coming from the JDK distribution (standard library) because the associated file will be none of the following types:
zinc/internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Lines 116 to 133 in c8e1f53
Which means we would emit an error, and fail compilation. The associated file of a Java class coming from the JDK distribution now uses the JRT file system, which only 2.12.{6,7} and 2.13.0-M5 understand.
This is arguably not such a big problem because java dependencies are always there and never change. So I believe that this won't affect the correctness of the incremental compiler. However, as is now in latest master, it will emit errors on JDK versions > 8 and fail compilation.
I propose we remove the emission of the errors for any class coming from the java standard library. We'll see how we can do this in the 2.12.x series. A complication is that the compiler bridge source works at the version series level rather than at a specific Scala version, which means we cannot compile the bridge with specific Scala code for versions < 2.12.6 and > 2.12.7.
The text was updated successfully, but these errors were encountered: