From aa91e9fd26d262335a98fa8d1468801b97033703 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Mon, 23 Sep 2024 20:47:44 +0200 Subject: [PATCH] Remove locale dependent FileSystemException check Fin SourceFile, files that do not exist are expected and related exceptions should be ignored. There are two relevant cases: scala> java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault().getPath("does-not-exist")) java.nio.file.NoSuchFileException: does-not-exist scala> java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault().getPath("regular-file-instead-of-directory/filename")) java.nio.file.FileSystemException: regular-file-instead-of-directory/filename: Not a directory Ideally, other I/O errors would be propagated to the caller. However, there is no reliable way to distinguish them based on the exceptions alone. In particular, the message cannot be checked, because it depends on the operating system and it is localized. Revert the addition of the check and just accept this. --- compiler/src/dotty/tools/dotc/util/SourceFile.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/util/SourceFile.scala b/compiler/src/dotty/tools/dotc/util/SourceFile.scala index 9da4f58f2deb..d1139e5217fa 100644 --- a/compiler/src/dotty/tools/dotc/util/SourceFile.scala +++ b/compiler/src/dotty/tools/dotc/util/SourceFile.scala @@ -275,12 +275,11 @@ object SourceFile { def apply(file: AbstractFile | Null, codec: Codec): SourceFile = // Files.exists is slow on Java 8 (https://rules.sonarsource.com/java/tag/performance/RSPEC-3725), - // so cope with failure; also deal with path prefix "Not a directory". + // so cope with failure. val chars = try new String(file.toByteArray, codec.charSet).toCharArray catch - case _: NoSuchFileException => Array.empty[Char] - case fse: FileSystemException if fse.getMessage.endsWith("Not a directory") => Array.empty[Char] + case _: FileSystemException => Array.empty[Char] if isScript(file, chars) then ScriptSourceFile(file, chars)