From 4ed22747dc95f1930fcd1a6008a40bf70623544a Mon Sep 17 00:00:00 2001 From: MkDev11 Date: Tue, 13 Jan 2026 11:31:43 -0500 Subject: [PATCH] [2.x] fix: Check cache file exists before reading in Eval (#8513) Fixes #8511 When loading a cached build definition, the code checked if the .class file exists but not the .cache file. If the .cache file was missing (deleted, corrupted, or from a partial compilation), it threw NoSuchFileException. Now both files are checked before using the cache. If either is missing, the build definition is recompiled. --- buildfile/src/main/scala/sbt/internal/Eval.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/buildfile/src/main/scala/sbt/internal/Eval.scala b/buildfile/src/main/scala/sbt/internal/Eval.scala index 1af9eb356..92c0f2d58 100644 --- a/buildfile/src/main/scala/sbt/internal/Eval.scala +++ b/buildfile/src/main/scala/sbt/internal/Eval.scala @@ -225,7 +225,8 @@ class Eval( val (extra, loader) = try backingDir match - case Some(backing) if classExists(backing, moduleName) => + case Some(backing) + if classExists(backing, moduleName) && cacheExists(backing, moduleName) => val loader = (parent: ClassLoader) => (new URLClassLoader(Array(backing.toUri.toURL), parent): ClassLoader) val extra = ev.read(cacheFile(backing, moduleName)) @@ -273,6 +274,9 @@ class Eval( private def classExists(dir: Path, name: String): Boolean = Files.exists(dir.resolve(s"$name.class")) + private def cacheExists(dir: Path, name: String): Boolean = + Files.exists(cacheFile(dir, name)) + private def getGeneratedFiles(moduleName: String): Seq[Path] = backingDir match case Some(dir) =>