Not planned
Description
Reproduction steps
Scala version: 2.13.11
Java version: 17.0.7
$ cat import_sun.scala
import sun._
$ scalac -deprecation -target:8 import_sun.scala
warning: -target is deprecated: Use -release instead to compile against the correct platform API.
1 warning
$ scalac -release:8 import_sun.scala
import_sun.scala:1: error: not found: object sun
import sun._
^
1 error
Problem
Compiling with the -target
flag gives a deprecation warning suggesting to use -release
instead. But switching using -release
means that the code no longer compiles.
If this is the intended behavior maybe the deprecation warnings/documentation should include more information of the differences between -target
and -release
.
Metadata
Metadata
Assignees
Labels
No labels
Activity
lrytz commentedon Jul 11, 2023
Compiling on JDK 17 with
-target:8
is not safeUsing
-release
instead fixes thatHowever, the corresponding classpath element that is used under
-release
instead of the JDK doesn't contain symbols for private API (such assun._
). So you need to build on JDK 8 in this case.som-snytt commentedon Jul 11, 2023
Duplicates #12643
The comment at the end of that ticket mentions
-javabootclasspath
and elsewhere:eejbyfeldt commentedon Jul 11, 2023
Thanks for clarifying.
Is this expected that using
--release 17
usingsun.*
classes compiles but fails at runtime?lrytz commentedon Jul 11, 2023
Yeah, the Scala compiler doesn't do access checks according to the Java module system (scala/scala-dev#529).
https://nipafx.dev/five-command-line-options-hack-java-module-system/ is a good article.
scala-maven-plugin
to 4.7.1 apache/spark#42899[SPARK-45144][BUILD] Downgrade `scala-maven-plugin` to 4.7.1
[SPARK-45144][BUILD] Downgrade `scala-maven-plugin` to 4.7.1
-system
, like javac) scala/scala#10801