Skip to content

Commit 930cff2

Browse files
committed
Fix loading tasty file from jar in concurrent setting
1 parent db3d321 commit 930cff2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,9 @@ class ClassfileParser(
798798
Array.empty[Byte]
799799
case Some(jar: ZipArchive) => // We are in a jar
800800
val jarFile = JarArchive.open(io.File(jar.jpath))
801-
try readTastyForClass(jarFile.jpath.resolve(classfile.path))
802-
finally jarFile.close()
801+
readTastyForClass(jarFile.jpath.resolve(classfile.path))
802+
// Do not close the file system as some other thread might might be using it
803+
// TODO find a way to safly close the file system or ose some other abstraction
803804
case _ =>
804805
readTastyForClass(classfile.jpath)
805806
}

compiler/src/dotty/tools/io/JarArchive.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.io
22

3-
import java.nio.file.{Files, FileSystem, FileSystems}
3+
import java.nio.file.{FileSystem, FileSystemAlreadyExistsException, FileSystems, Files}
44

55
import scala.collection.JavaConverters._
66

@@ -9,7 +9,7 @@ import scala.collection.JavaConverters._
99
* that be can used as the compiler's output directory.
1010
*/
1111
class JarArchive private (root: Directory) extends PlainDirectory(root) {
12-
def close() = jpath.getFileSystem().close()
12+
def close(): Unit = jpath.getFileSystem().close()
1313
}
1414

1515
object JarArchive {
@@ -28,8 +28,12 @@ object JarArchive {
2828
// https://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html
2929
val env = Map("create" -> create.toString).asJava
3030
val uri = java.net.URI.create("jar:file:" + path.toAbsolute.path)
31-
val fs = FileSystems.newFileSystem(uri, env)
32-
31+
val fs = {
32+
try FileSystems.newFileSystem(uri, env)
33+
catch {
34+
case _: FileSystemAlreadyExistsException => FileSystems.getFileSystem(uri)
35+
}
36+
}
3337
val root = fs.getRootDirectories().iterator.next()
3438
new JarArchive(Directory(root))
3539
}

0 commit comments

Comments
 (0)