Skip to content

AccessDeniedException when scanning filesystem root due to Files.walk without error handling #609

Description

@nixel2007

Problem

When MDClasses.findFiles() (or MDClasses.createSolution()) is called with a path that is the filesystem root (/) or contains protected directories (e.g. /sys/kernel/tracing/), it throws an unhandled AccessDeniedException wrapped in UncheckedIOException:

java.io.UncheckedIOException: java.nio.file.AccessDeniedException: /sys/kernel/tracing/osnoise
  at com.github._1c_syntax.bsl.languageserver.context.ServerContext.computeConfigurationMetadata(ServerContext.java:435)
  ...

Root cause

Files.walk() propagates AccessDeniedException as an UncheckedIOException. The caller has no reasonable way to predict which paths will be inaccessible on a given OS/environment (e.g. Linux /sys, /proc, container-mounted filesystems).

Expected behavior

findFiles() / createSolution() should silently skip directories that cannot be accessed, similar to how find command behaves with -maxdepth or permission errors. This can be done by replacing Files.walk() with Files.walkFileTree() and returning FileVisitResult.CONTINUE from visitFileFailed() when the exception is an AccessDeniedException.

Suggested fix

Files.walkFileTree(root, new SimpleFileVisitor<>() {
    @Override
    public FileVisitResult visitFileFailed(Path file, IOException exc) {
        if (exc instanceof AccessDeniedException) {
            return FileVisitResult.CONTINUE; // skip inaccessible paths
        }
        throw new UncheckedIOException(exc);
    }
    // ... visitFile as before
});

Reproducer

Call MDClasses.createSolution(Path.of("/"), settings) on Linux — it will eventually hit /sys/kernel/tracing/osnoise and throw.

Observed in BSL Language Server CI on Ubuntu runners: https://github.com/1c-syntax/bsl-language-server/actions/runs/25785327480/job/75737261066

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions