quarkusio/quarkus · error · IllegalStateException

Unable to read file '" + f + "'

Error message

Unable to read file '" + f + "'

What it means

ServiceBinding.getFilenameToContentMap reads every regular file in a binding directory with Files.readString and wraps any IOException in IllegalStateException('Unable to read file X'). One unreadable file (wrong permissions, unreadable encoding, or vanishing mid-read) aborts construction of the whole binding.

Source

Thrown at extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/ServiceBinding.java:89

        File[] files = directory.toFile().listFiles(new FileFilter() {
            @Override
            public boolean accept(File f) {
                try {
                    return !Files.isHidden(f.toPath()) && !Files.isDirectory(f.toPath());
                } catch (IOException e) {
                    throw new IllegalStateException("Unable to determine if file '" + f + "' is a regular file", e);
                }
            }
        });

        Map<String, String> result = new HashMap<>();
        if (files != null) {
            for (File f : files) {
                try {
                    result.put(f.toPath().getFileName().toString(),
                            Files.readString(f.toPath()).trim());
                } catch (IOException e) {
                    throw new IllegalStateException("Unable to read file '" + f + "'", e);
                }
            }
        }
        return result;
    }

    public String getName() {
        return name;
    }

    public Map<String, String> getProperties() {
        return properties;
    }

    public String getType() {
        return type;
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check and fix read permissions on the file named in the message (chmod/ownership).
  2. Ensure the secret volume is fully mounted and the file exists at read time.
  3. Remove non-text/binary files from the binding directory — every regular file is read as a string.
  4. Run the container as the user that owns the mounted files, or relax the mount's defaultMode.
  5. Check the wrapped IOException cause for the precise OS error.

Example fix

# before: mounted secret unreadable by app user
defaultMode: 0600  # app runs as uid 1001
# after
defaultMode: 0444
# or chown 1001 the files / run container as matching uid
Defensive patterns

Strategy: validation

Validate before calling

static void assertAllFilesReadable(Path dir) throws IOException {
    try (var s = Files.list(dir)) {
        s.filter(Files::isRegularFile)
         .forEach(f -> {
             if (!Files.isReadable(f)) throw new IllegalStateException("Unreadable binding file: " + f);
             if (!f.getFileName().toString().equals("type") && isBinary(f)) {
                 throw new IllegalStateException("Non-text file in binding dir: " + f);
             }
         });
    }
}

Try / catch

try {
    loadBindings();
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("Unable to read file")) {
        log.error("Binding file unreadable: {} — fix permissions/mount", e.getMessage());
    }
}

Prevention

When it happens

Trigger: A file in the binding directory exists and passes the accept filter, but Files.readString fails — no read permission, I/O error on a mounted volume, or the file is deleted/replaced between listing and read.

Common situations: Credentials files mounted with restrictive permissions the app user can't read; partially mounted secret volumes; binary or non-UTF8 files in the binding directory breaking readString; container user mismatch (root-created files, non-root app).

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/b0701df0e4c92c0d. Report an issue: GitHub.