Skip to content

Commit d97376b

Browse files
authored
Merge pull request scala#9671 from retronym/topic/ct-sym-release-cache
Include -release arg in cache key for ct.sym classpath element
2 parents b2b8816 + 31d8d05 commit d97376b

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/compiler/scala/tools/nsc/classpath/DirectoryClassPath.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
130130
object JrtClassPath {
131131
import java.nio.file._, java.net.URI
132132
private val jrtClassPathCache = new FileBasedCache[Unit, JrtClassPath]()
133-
private val ctSymClassPathCache = new FileBasedCache[Unit, CtSymClassPath]()
133+
private val ctSymClassPathCache = new FileBasedCache[String, CtSymClassPath]()
134134
def apply(release: Option[String], closeableRegistry: CloseableRegistry): Option[ClassPath] = {
135135
import scala.util.Properties._
136136
if (!isJavaAtLeast("9")) None
@@ -149,7 +149,7 @@ object JrtClassPath {
149149
val ctSym = Paths.get(javaHome).resolve("lib").resolve("ct.sym")
150150
if (Files.notExists(ctSym)) None
151151
else {
152-
val classPath = ctSymClassPathCache.getOrCreate((), ctSym :: Nil, () => new CtSymClassPath(ctSym, v.toInt), closeableRegistry, true)
152+
val classPath = ctSymClassPathCache.getOrCreate(v, ctSym :: Nil, () => new CtSymClassPath(ctSym, v.toInt), closeableRegistry, true)
153153
Some(classPath)
154154
}
155155
} catch {

src/reflect/scala/reflect/io/ZipArchive.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ final class FileZipArchive(file: JFile, release: Option[String]) extends ZipArch
220220
override def close(): Unit = { zipFilePool.release(zipFile) }
221221
}
222222
}
223-
override def sizeOption: Option[Int] = Some(size) // could be stale
223+
override def sizeOption: Option[Int] = Some(size)
224224
}
225225

226226
private[this] val dirs = new java.util.HashMap[String, DirEntry]()
@@ -236,16 +236,19 @@ final class FileZipArchive(file: JFile, release: Option[String]) extends ZipArch
236236
if (!zipEntry.getName.startsWith("META-INF/versions/")) {
237237
if (!zipEntry.isDirectory) {
238238
val dir = getDir(dirs, zipEntry)
239+
val mrEntry = if (release.isDefined) {
240+
zipFile.getEntry(zipEntry.getName)
241+
} else zipEntry
239242
val f =
240243
if (ZipArchive.closeZipFile)
241244
new LazyEntry(
242245
zipEntry.getName,
243-
zipEntry.getTime,
244-
zipEntry.getSize.toInt)
246+
mrEntry.getTime,
247+
mrEntry.getSize.toInt)
245248
else
246249
new LeakyEntry(zipEntry.getName,
247-
zipEntry.getTime,
248-
zipEntry.getSize.toInt)
250+
mrEntry.getTime,
251+
mrEntry.getSize.toInt)
249252

250253
dir.entries(f.name) = f
251254
}

test/junit/scala/tools/nsc/classpath/MultiReleaseJarTest.scala

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import java.io.ByteArrayOutputStream
44
import java.nio.file.{FileSystems, Files, Path}
55
import java.util.jar.Attributes
66
import java.util.jar.Attributes.Name
7-
87
import org.junit.{Assert, Test}
98

10-
import scala.tools.nsc.{Global, Settings}
9+
import scala.tools.nsc.{CloseableRegistry, Global, Settings}
1110
import scala.tools.testing.BytecodeTesting
1211
import scala.util.Properties
1312

@@ -22,6 +21,7 @@ class MultiReleaseJarTest extends BytecodeTesting {
2221
// TODO test fails if both Global runs look at the same JAR on disk. Caching problem in our classpath implementation?
2322
// val temp2 = temp1
2423
val temp2 = Files.createTempFile("mr-jar-test-", ".jar")
24+
val cleanup = new CloseableRegistry
2525

2626
try {
2727
def code(newApi: String) = s"package p1; abstract class Versioned { def oldApi: Int; $newApi }"
@@ -39,6 +39,7 @@ class MultiReleaseJarTest extends BytecodeTesting {
3939
settings.usejavacp.value = true
4040
settings.classpath.value = jarPath.toAbsolutePath.toString
4141
val g = new Global(settings)
42+
cleanup.registerClosable(g)
4243
settings.release.value = release
4344
new g.Run
4445
val decls = g.rootMirror.staticClass("p1.Versioned").info.decls.filterNot(_.isConstructor).map(_.name.toString).toList.sorted
@@ -47,28 +48,38 @@ class MultiReleaseJarTest extends BytecodeTesting {
4748

4849
Assert.assertEquals(List("newApi", "oldApi"), declsOfC(temp1, "9"))
4950
Assert.assertEquals(List("oldApi"), declsOfC(temp2, "8"))
50-
} finally
51+
} finally {
52+
cleanup.close()
5153
List(temp1, temp2).foreach(Files.deleteIfExists)
54+
}
5255
}
5356

5457
@Test
5558
def ctSymTest(): Unit = {
5659
if (!Properties.isJavaAtLeast("9")) { println("skipping mrJar() on old JDK"); return} // TODO test that the compiler warns that --release is unsupported.
60+
val cleanup = new CloseableRegistry
5761

5862
def lookup(className: String, release: String): Boolean = {
5963
val settings = new Settings()
6064
settings.usejavacp.value = true
6165
val g = new Global(settings)
66+
cleanup.registerClosable(g)
6267
import g._
6368
settings.release.value = release
6469
new Run
6570
rootMirror.getClassIfDefined(TypeName(className)) != NoSymbol
6671
}
67-
Assert.assertTrue(lookup("java.lang.invoke.LambdaMetafactory", "8"))
68-
Assert.assertFalse(lookup("java.lang.invoke.LambdaMetafactory", "7"))
69-
Assert.assertTrue(lookup("java.lang.invoke.LambdaMetafactory", "9"))
72+
try {
73+
Assert.assertTrue(lookup("java.lang.invoke.LambdaMetafactory", "8"))
74+
Assert.assertFalse(lookup("java.lang.invoke.LambdaMetafactory", "7"))
75+
Assert.assertTrue(lookup("java.lang.invoke.LambdaMetafactory", "9"))
76+
} finally {
77+
cleanup.close()
78+
}
7079
}
7180

81+
82+
7283
private def createManifest = {
7384
val manifest = new java.util.jar.Manifest()
7485
manifest.getMainAttributes.put(Name.MANIFEST_VERSION, "1.0")

0 commit comments

Comments
 (0)