From bc0f86df07436db27261b91edd8473d2a318cc32 Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Thu, 21 Nov 2024 19:57:14 +0100 Subject: [PATCH] [compiler] Avoid computing zinc stamps for JDK 9+ module .sig files/paths #SCL-22939 fixed - These paths really do not like being accessed through the regular Java IO means, throwing ClosedFileSystemException instances when accessed concurrently, like we do in the Scala compile server. - https://github.com/sbt/zinc/issues/1383 --- .../scala/local/zinc/StampReader.scala | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/scala/compile-server/src/org/jetbrains/jps/incremental/scala/local/zinc/StampReader.scala b/scala/compile-server/src/org/jetbrains/jps/incremental/scala/local/zinc/StampReader.scala index 01f65916809..de556dafc33 100644 --- a/scala/compile-server/src/org/jetbrains/jps/incremental/scala/local/zinc/StampReader.scala +++ b/scala/compile-server/src/org/jetbrains/jps/incremental/scala/local/zinc/StampReader.scala @@ -1,8 +1,28 @@ package org.jetbrains.jps.incremental.scala.local.zinc -import sbt.internal.inc.{PlainVirtualFileConverter, Stamps} -import xsbti.compile.analysis.ReadStamps +import sbt.internal.inc.{FarmHash, PlainVirtualFileConverter, Stamper, Stamps} +import xsbti.VirtualFileRef +import xsbti.compile.analysis.{ReadStamps, Stamp} private[local] object StampReader { - val Instance: ReadStamps = Stamps.timeWrapBinaryStamps(PlainVirtualFileConverter.converter) + + private def avoidSigs(ref: VirtualFileRef): Stamp = { + if (ref.id.endsWith(".sig")) { + val path = PlainVirtualFileConverter.converter.toPath(ref) + if (path.getClass.getName == "jdk.nio.zipfs.ZipPath") + return FarmHash.fromLong(path.##.toLong) + } + fallback(ref) + } + + private def fallback(ref: VirtualFileRef): Stamp = + Stamper.forHashInRootPaths(PlainVirtualFileConverter.converter).apply(ref) + + private val uncached: ReadStamps = Stamps.uncachedStamps( + avoidSigs, + Stamper.forContentHash, + avoidSigs + ) + + val Instance: ReadStamps = Stamps.timeWrapBinaryStamps(uncached, PlainVirtualFileConverter.converter) }