Skip to content

Commit

Permalink
Merge pull request #10335 from SethTisue/restarr-jdk20
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue committed Mar 9, 2023
2 parents 44c6006 + 39762a7 commit 35e3eff
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
java: [8, 11, 17]
java: [8, 11, 17, 20-ea]
runs-on: ${{matrix.os}}
steps:
- run: git config --global core.autocrlf false
Expand Down
6 changes: 6 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ lazy val commonSettings = instanceSettings ++ clearSourceAndResourceDirectories
compileOrder := CompileOrder.JavaThenScala,
projectFolder := thisProject.value.id, // overridden in configureAsSubproject
Compile / javacOptions ++= Seq("-g", "-source", "1.8", "-target", "1.8", "-Xlint:unchecked"),
Compile / javacOptions ++= (
if (scala.util.Properties.isJavaAtLeast("20"))
Seq("-Xlint:-options") // allow `-source 1.8` and `-target 1.8`
else
Seq()),
Compile / javacOptions ++= Seq("-g", "-source", "1.8", "-target", "1.8", "-Xlint:unchecked"),
Compile / unmanagedJars := Seq.empty, // no JARs in version control!
Compile / sourceDirectory := baseDirectory.value,
Compile / unmanagedSourceDirectories := List(baseDirectory.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package scala.tools.nsc.classpath

import java.io.{Closeable, File}
import java.net.URL
import java.net.{URI, URL}

import scala.reflect.io.{AbstractFile, PlainFile, PlainNioFile}
import scala.tools.nsc.util.{ClassPath, ClassRepresentation, EfficientClassPath}
Expand Down Expand Up @@ -209,7 +209,7 @@ final class JrtClassPath(fs: java.nio.file.FileSystem) extends ClassPath with No
if (inPackage.isRoot) ClassPathEntries(packages(inPackage), Nil)
else ClassPathEntries(packages(inPackage), classes(inPackage))

def asURLs: Seq[URL] = Seq(new URL("jrt:/"))
def asURLs: Seq[URL] = Seq(new URI("jrt:/").toURL)
// We don't yet have a scheme to represent the JDK modules in our `-classpath`.
// java models them as entries in the new "module path", we'll probably need to follow this.
def asClassPathStrings: Seq[String] = Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package scala.tools.nsc.classpath
import scala.tools.nsc.util.ClassRepresentation
import scala.reflect.io.{AbstractFile, VirtualDirectory}
import FileUtils._
import java.net.URL
import java.net.{URI, URL}

import scala.reflect.internal.util.AbstractFileClassLoader
import scala.tools.nsc.util.ClassPath
Expand All @@ -35,7 +35,7 @@ case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath wi
def isPackage(f: AbstractFile): Boolean = f.isPackage

// mimic the behavior of the old nsc.util.DirectoryClassPath
def asURLs: Seq[URL] = Seq(new URL("file://_VIRTUAL_/" + dir.name))
def asURLs: Seq[URL] = Seq(new URI("file://_VIRTUAL_/" + dir.name).toURL)
def asClassPathStrings: Seq[String] = Seq(dir.path)
override def findClass(className: String): Option[ClassRepresentation] = findClassFile(className) map ClassFileEntryImpl

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/scala/tools/nsc/util/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package util

import io.{AbstractFile, Directory, File, Jar}
import java.net.MalformedURLException
import java.net.URL
import java.net.{URI, URL}
import java.util.regex.PatternSyntaxException

import File.pathSeparator
Expand Down Expand Up @@ -184,7 +184,7 @@ object ClassPath {
}

def specToURL(spec: String): Option[URL] =
try Some(new URL(spec))
try Some(new URI(spec).toURL)
catch { case _: MalformedURLException => None }

def manifests: List[java.net.URL] = {
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/io/Source.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ object Source {
/** same as fromURL(new URL(s))
*/
def fromURL(s: String)(implicit codec: Codec): BufferedSource =
fromURL(new URL(s))(codec)
fromURL(new URI(s).toURL)(codec)

/** same as fromInputStream(url.openStream())(Codec(enc))
*/
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/util/Using.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ object Using {
}

private def preferentiallySuppress(primary: Throwable, secondary: Throwable): Throwable = {
@annotation.nowarn("cat=deprecation") // avoid warning on mention of ThreadDeath
def score(t: Throwable): Int = t match {
case _: VirtualMachineError => 4
case _: LinkageError => 3
Expand Down
1 change: 1 addition & 0 deletions src/library/scala/util/control/NonFatal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ object NonFatal {
/**
* Returns true if the provided `Throwable` is to be considered non-fatal, or false if it is to be considered fatal
*/
@annotation.nowarn("cat=deprecation") // avoid warning on mention of ThreadDeath
def apply(t: Throwable): Boolean = t match {
// VirtualMachineError includes OutOfMemoryError and other fatal errors
case _: VirtualMachineError | _: ThreadDeath | _: InterruptedException | _: LinkageError | _: ControlThrowable => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package reflect.internal.util
import scala.collection.mutable
import scala.collection.immutable.ArraySeq
import scala.reflect.io.AbstractFile
import java.net.{URL, URLConnection, URLStreamHandler}
import java.net.{URI, URL, URLConnection, URLStreamHandler}
import java.security.cert.Certificate
import java.security.{CodeSource, ProtectionDomain}
import java.util.{Collections => JCollections, Enumeration => JEnumeration}
Expand Down Expand Up @@ -76,6 +76,10 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
else
defineClass(name, bytes, 0, bytes.length, protectionDomain)
}

// on JDK 20 the URL constructor we're using is deprecated, but the recommended
// replacement, URL.of, doesn't exist on JDK 8
@annotation.nowarn("cat=deprecation")
override protected def findResource(name: String): URL = findAbstractFile(name) match {
case null => null
case file => new URL(null, s"memory:${file.path}", new URLStreamHandler {
Expand All @@ -85,6 +89,7 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
}
})
}

override protected def findResources(name: String): JEnumeration[URL] = findResource(name) match {
case null => JCollections.enumeration(JCollections.emptyList[URL]) //JCollections.emptyEnumeration[URL]
case url => JCollections.enumeration(JCollections.singleton(url))
Expand All @@ -98,7 +103,7 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
val n = s.lastIndexOf('!')
if (n < 0) null else {
val path = s.substring(0, n)
new ProtectionDomain(new CodeSource(new URL(path), null.asInstanceOf[Array[Certificate]]), null, this, null)
new ProtectionDomain(new CodeSource(new URI(path).toURL, null.asInstanceOf[Array[Certificate]]), null, this, null)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.jline.reader.impl.{CompletionMatcherImpl, DefaultParser, LineReaderIm
import org.jline.terminal.Terminal

import java.io.{ByteArrayInputStream, File}
import java.net.{MalformedURLException, URL}
import java.net.{MalformedURLException, URI, URL}
import java.util.{List => JList}
import scala.io.Source
import scala.reflect.internal.Chars
Expand Down Expand Up @@ -80,7 +80,7 @@ object Reader {
sys.props
.get("jline.inputrc")
.flatMap { path =>
try Some(new URL(path))
try Some(new URI(path).toURL)
catch {
case _: MalformedURLException =>
Some(new File(path).toURI.toURL)
Expand Down
6 changes: 3 additions & 3 deletions src/repl/scala/tools/nsc/interpreter/Power.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package scala.tools.nsc.interpreter

import java.io.InputStream
import java.net.URL
import java.net.{URI, URL}

import scala.collection.mutable
import scala.io.Codec
Expand Down Expand Up @@ -248,9 +248,9 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
class RichReplString(s: String) {
// make an url out of the string
def u: URL = (
if (s contains ":") new URL(s)
if (s contains ":") new URI(s).toURL
else if (new java.io.File(s).exists) new java.io.File(s).toURI.toURL
else new URL("http://" + s)
else new URI("http://" + s).toURL
)
}
class RichInputStream(in: InputStream)(implicit codec: Codec) {
Expand Down
2 changes: 1 addition & 1 deletion src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
case "TPL_NAME" => tplName
}
val patchedString = patches.replaceAllIn(settings.docsourceurl.value, m => java.util.regex.Matcher.quoteReplacement(substitute(m.group(1))) )
new java.net.URL(patchedString)
new java.net.URI(patchedString).toURL
}
else None
}
Expand Down
5 changes: 3 additions & 2 deletions test/files/jvm/scala-concurrent-tck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.concurrent.{
Awaitable,
blocking
}
import scala.annotation.tailrec
import scala.annotation.{nowarn, tailrec}
import scala.concurrent.duration._
import scala.reflect.{classTag, ClassTag}
import scala.tools.testkit.AssertUtil.{Fast, Slow, assertThrows, waitFor, waitForIt}
Expand Down Expand Up @@ -864,7 +864,8 @@ class Exceptions extends TestBase {

class GlobalExecutionContext extends TestBase {
import ExecutionContext.Implicits._


@nowarn("cat=deprecation") // Thread.getID is deprecated since JDK 19
def testNameOfGlobalECThreads(): Unit = once {
done => Future({
val expectedName = "scala-execution-context-global-"+ Thread.currentThread.getId
Expand Down
3 changes: 3 additions & 0 deletions test/files/run/reflection-magicsymbols-invoke.check
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ method notify: (): Unit
method notifyAll: (): Unit
method synchronized: [T0](x$1: T0): T0
method toString: (): String
#partest java20+
method wait0: (x$1: Long): Unit
#partest
method wait: (): Unit
method wait: (x$1: Long): Unit
method wait: (x$1: Long, x$2: Int): Unit
Expand Down
6 changes: 3 additions & 3 deletions test/files/run/t6989.check
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ isProtected = false
isPublic = true
privateWithin = <none>
============
#partest !java18
#partest !java18+
sym = value this$0, signature = foo.JavaClass_1, owner = class $PrivateJavaClass
isPrivate = false
isProtected = false
Expand All @@ -133,7 +133,7 @@ isProtected = false
isPublic = true
privateWithin = <none>
============
#partest !java18
#partest !java18+
sym = value this$0, signature = foo.JavaClass_1, owner = class $ProtectedJavaClass
isPrivate = false
isProtected = false
Expand All @@ -159,7 +159,7 @@ isProtected = false
isPublic = true
privateWithin = <none>
============
#partest !java18
#partest !java18+
sym = value this$0, signature = foo.JavaClass_1, owner = class $PublicJavaClass
isPrivate = false
isProtected = false
Expand Down
19 changes: 18 additions & 1 deletion test/files/run/t9529.check
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ u: List(@anns.Ann_0$Container(value={@anns.Ann_0(name="u", value="you"), @anns.A

List(@anns.Ann_0$Container(value={@anns.Ann_0(name="<init>", value="constructor"), @anns.Ann_0(name="<init>", value="initializer")}))

#partest java15+
#partest java17
A: List()
B: List(@java.lang.Deprecated(forRemoval=false, since=""))
C: List(@anns.Ann_0(name="C", value="see"))
Expand All @@ -49,3 +49,20 @@ u: List(@anns.Ann_0$Container({@anns.Ann_0(name="u", value="you"), @anns.Ann_0(n

List(@anns.Ann_0$Container({@anns.Ann_0(name="<init>", value="constructor"), @anns.Ann_0(name="<init>", value="initializer")}))

#partest java20+
A: List()
B: List(@java.lang.Deprecated(forRemoval=false, since=""))
C: List(@anns.Ann_0(name="C", value="see"))
D: List(@anns.Ann_0.Container({@anns.Ann_0(name="D", value="dee"), @anns.Ann_0(name="D", value="dye")}))

x: List(@anns.Ann_0(name="x", value="eks"))
y: List(@anns.Ann_0.Container({@anns.Ann_0(name="y", value="why"), @anns.Ann_0(name="y", value="wye")}))

t: List(@anns.Ann_0(name="t", value="tee"))
u: List(@anns.Ann_0.Container({@anns.Ann_0(name="u", value="you"), @anns.Ann_0(name="u", value="yew")}))

1: List(@anns.Ann_0(name="1", value="one"))
2: List(@anns.Ann_0.Container({@anns.Ann_0(name="2", value="two"), @anns.Ann_0(name="2", value="tew")}))

List(@anns.Ann_0.Container({@anns.Ann_0(name="<init>", value="constructor"), @anns.Ann_0(name="<init>", value="initializer")}))

2 changes: 1 addition & 1 deletion test/junit/scala/runtime/FloatBoxingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FloatBoxingTest extends SideEffectTest with AllocationTest {
assertEquals(57, nonAllocating(value.byteValue()))
}
@Test def str(): Unit = {
val cost = allocationInfo(java.lang.Double.toString(value))
val cost = allocationInfo(java.lang.Float.toString(value))
assertEquals("12345.0", exactAllocates(cost.min)(value.toString()))
}
@Test def hash1(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class MultiReleaseJarTest extends BytecodeTesting {
}
try {
Assert.assertTrue(lookup("java.lang.invoke.LambdaMetafactory", "8"))
Assert.assertFalse(lookup("java.lang.invoke.LambdaMetafactory", "7"))
if (!Properties.isJavaAtLeast("20"))
Assert.assertFalse(lookup("java.lang.invoke.LambdaMetafactory", "7"))
Assert.assertTrue(lookup("java.lang.invoke.LambdaMetafactory", "9"))
} finally {
cleanup.close()
Expand Down
2 changes: 2 additions & 0 deletions test/junit/scala/util/TryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class TryTest {
assertEquals(Failure(e), Failure[Int](e).map(_ => throw e2))
}

@deprecated("ThreadDeath is deprecated on JDK 20", "")
@Test def `map when there is a fatal exception`(): Unit = {
val e3 = new ThreadDeath
assertThrows[ThreadDeath] {
Expand All @@ -82,6 +83,7 @@ class TryTest {
val e2 = new Exception
assertEquals(Failure(e), Failure[Int](e).flatMap[Int](_ => throw e2))
}
@deprecated("ThreadDeath is deprecated on JDK 20", "")
@Test def `flatMap when there is a fatal exception`(): Unit = {
val e3 = new ThreadDeath
assertThrows[ThreadDeath] {
Expand Down
1 change: 1 addition & 0 deletions test/junit/scala/util/UsingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.annotation.unused
import scala.reflect.ClassTag
import scala.util.control.ControlThrowable

@deprecated("ThreadDeath is deprecated on JDK 20", "")
class UsingTest {
import UsingTest._

Expand Down
8 changes: 4 additions & 4 deletions test/scaladoc/run/doc-source-url-java.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* additional information regarding copyright ownership.
*/

import java.net.URL
import java.net.URI

import scala.tools.nsc.ScalaDocReporter
import scala.tools.nsc.doc.Universe
Expand All @@ -26,14 +26,14 @@ object Test extends ScaladocModelTest {

override def model: Option[Universe] = newDocFactory.makeUniverse(Left(List(resourceFile)))

def scaladocSettings = "-doc-source-url file:€{FILE_PATH}||€{FILE_EXT}||€{FILE_PATH_EXT}||€{FILE_LINE}"
def scaladocSettings = "-doc-source-url file:€{FILE_PATH}@@€{FILE_EXT}@@€{FILE_PATH_EXT}@@€{FILE_LINE}"

def testModel(rootPackage: Package) = {
import access._

val clazz = rootPackage._class("WithSource")

val expect = s"file:test/scaladoc/resources/doc-source-url||.java||test/scaladoc/resources/doc-source-url.java||13"
assert(clazz.sourceUrl.contains(new URL(expect)), s"got ${clazz.sourceUrl}")
val expect = s"file:test/scaladoc/resources/doc-source-url@@.java@@test/scaladoc/resources/doc-source-url.java@@13"
assert(clazz.sourceUrl.contains(new URI(expect).toURL), s"got ${clazz.sourceUrl}")
}
}
8 changes: 4 additions & 4 deletions test/scaladoc/run/doc-source-url.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* additional information regarding copyright ownership.
*/

import java.net.URL
import java.net.URI

import scala.tools.nsc.ScalaDocReporter
import scala.tools.nsc.doc.Universe
Expand All @@ -26,14 +26,14 @@ object Test extends ScaladocModelTest {

override def model: Option[Universe] = newDocFactory.makeUniverse(Left(List(resourceFile)))

def scaladocSettings = "-doc-source-url file:€{FILE_PATH}||€{FILE_EXT}||€{FILE_PATH_EXT}||€{FILE_LINE}"
def scaladocSettings = "-doc-source-url file:€{FILE_PATH}@@€{FILE_EXT}@@€{FILE_PATH_EXT}@@€{FILE_LINE}"

def testModel(rootPackage: Package) = {
import access._

val clazz = rootPackage._class("WithSource")

val expect = s"file:test/scaladoc/resources/doc-source-url||.scala||test/scaladoc/resources/doc-source-url.scala||13"
assert(clazz.sourceUrl.contains(new URL(expect)), s"got ${clazz.sourceUrl}")
val expect = s"file:test/scaladoc/resources/doc-source-url@@.scala@@test/scaladoc/resources/doc-source-url.scala@@13"
assert(clazz.sourceUrl.contains(new URI(expect).toURL), s"got ${clazz.sourceUrl}")
}
}
2 changes: 1 addition & 1 deletion versions.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Scala version used for bootstrapping (see README.md)
starr.version=2.13.10
starr.version=2.13.11-M1

# These are the versions of the modules that go with this release.
# Artifact dependencies:
Expand Down

0 comments on commit 35e3eff

Please sign in to comment.