Skip to content

Commit 699e0cb

Browse files
authored
Remove locale dependent FileSystemException check (#21633)
In 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. --- Resolves the following concrete bug: 0. Use an operating system that localizes strerror, like Debian. 1. Check out https://github.com/lichess-org/lila before lichess-org/lila@8610e6f 2. `LANGUAGE=fr sbt compile` 3. ICE with `java.nio.file.FileSystemException: lila/src/main/scala/future.scala: N'est pas un dossier` ([stacktrace](https://gist.github.com/ornicar/4a7b136d2220f4c1fd43e920956f67b4)) Not sure how to exercise locale dependent issues in a unit test. --- cc @som-snytt in case I misinterpreted 159da44 and distinguishing other I/O errors is not optional.
2 parents c533443 + aa91e9f commit 699e0cb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

compiler/src/dotty/tools/dotc/util/SourceFile.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,11 @@ object SourceFile {
276276

277277
def apply(file: AbstractFile | Null, codec: Codec): SourceFile =
278278
// Files.exists is slow on Java 8 (https://rules.sonarsource.com/java/tag/performance/RSPEC-3725),
279-
// so cope with failure; also deal with path prefix "Not a directory".
279+
// so cope with failure.
280280
val chars =
281281
try new String(file.toByteArray, codec.charSet).toCharArray
282282
catch
283-
case _: NoSuchFileException => Array.empty[Char]
284-
case fse: FileSystemException if fse.getMessage.endsWith("Not a directory") => Array.empty[Char]
283+
case _: FileSystemException => Array.empty[Char]
285284

286285
if isScript(file, chars) then
287286
ScriptSourceFile(file, chars)

0 commit comments

Comments
 (0)