Skip to content

Commit 269870d

Browse files
Fix ClosedFileSystemException sometimes seen with ct.sym (#112)
1 parent 8fffd56 commit 269870d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

backend/src/main/scala/sbt/internal/inc/bloop/internal/BloopAnalysisCallback.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package sbt.internal.inc.bloop.internal
22

33
import java.io.File
4+
import java.nio.file.FileSystem
5+
import java.nio.file.FileSystems
46
import java.nio.file.Path
57
import java.{util => ju}
68

@@ -75,6 +77,7 @@ final class BloopAnalysisCallback(
7577
private[this] val reportedProblems = new mutable.HashMap[Path, mutable.ListBuffer[Problem]]
7678
private[this] val mainClasses = new mutable.HashMap[Path, mutable.ListBuffer[String]]
7779
private[this] val binaryDeps = new mutable.HashMap[Path, mutable.HashSet[Path]]
80+
private[this] val binaryDepsZips = new mutable.HashMap[String, FileSystem]
7881

7982
// source file to set of generated (class file, binary class name); only non local classes are stored here
8083
private[this] val nonLocalClasses = new mutable.HashMap[Path, mutable.HashSet[(Path, String)]]
@@ -139,13 +142,28 @@ final class BloopAnalysisCallback(
139142
add(intSrcDeps, sourceClassName, InternalDependency.of(sourceClassName, onClassName, context))
140143
}
141144

145+
private[this] def safePath(path: Path): Path =
146+
path.getFileSystem match {
147+
case fs if fs.getClass.getName == "jdk.nio.zipfs.ZipFileSystem" =>
148+
// The FileSystem of path might be closed when we read path later on, so
149+
// we try to duplicate it with a FileSystem instance of our own, that we know
150+
// won't be closed by then.
151+
val fs0 = binaryDepsZips.getOrElseUpdate(
152+
fs.toString,
153+
// Resource management: we let those be closed upon GC… Hope this isn't a problem on Windows…
154+
FileSystems.newFileSystem(java.nio.file.Paths.get(fs.toString))
155+
)
156+
fs0.getPath(path.toString)
157+
case _ => path
158+
}
159+
142160
private[this] def externalBinaryDependency(
143161
binary: Path,
144162
className: String,
145163
source: VirtualFileRef
146164
): Unit = {
147-
binaryClassName.put(binary, className)
148-
add(binaryDeps, converter.toPath(source), binary)
165+
binaryClassName.put(safePath(binary), className)
166+
add(binaryDeps, converter.toPath(source), safePath(binary))
149167
}
150168

151169
private[this] def externalSourceDependency(

0 commit comments

Comments
 (0)