quarkusio/quarkus · error · IllegalArgumentException

File does not exist: ${file}

Error message

File does not exist: ${file}

What it means

PathPart represents a byte-range of a file to be sent as a REST response body. The constructor eagerly validates its inputs and throws this IllegalArgumentException when the given Path does not exist on the filesystem at construction time, so bad inputs fail fast instead of failing mid-response streaming.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/PathPart.java:37

     * The starting byte of the file
     */
    public final long offset;

    /**
     * The number of bytes to send
     */
    public final long count;

    /**
     * Create a new partial {@link Path} object.
     *
     * @param file The file to send
     * @param offset The starting byte of the file (must be >= 0)
     * @param count The number of bytes to send (must be >= 0 and offset+count <= file size)
     */
    public PathPart(Path file, long offset, long count) {
        if (!Files.exists(file))
            throw new IllegalArgumentException("File does not exist: " + file);
        if (!Files.isRegularFile(file))
            throw new IllegalArgumentException("File is not a regular file: " + file);
        if (!Files.isReadable(file))
            throw new IllegalArgumentException("File cannot be read: " + file);
        if (offset < 0)
            throw new IllegalArgumentException("Offset (" + offset + ") must be >= 0: " + file);
        if (count < 0)
            throw new IllegalArgumentException("Count (" + count + ") must be >= 0: " + file);
        long fileLength;
        try {
            fileLength = Files.size(file);
            if ((offset + count) > fileLength)
                throw new IllegalArgumentException(
                        "Offset + count (" + (offset + count) + ") larger than file size (" + fileLength + "): " + file);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        this.file = file;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Verify the exact path exists with `Files.exists(file)` (and log `file.toAbsolutePath()`) before constructing PathPart.
  2. Fix path resolution: use absolute paths or resolve relative paths against a known base directory.
  3. Check that any step that creates the file actually ran (e.g. the upload/export step), and check for cleanup jobs deleting the file.
  4. Handle the IllegalArgumentException in the endpoint and return 404 instead of an error response.

Example fix

// before
PathPart part = new PathPart(Path.of(config.downloadDir(), name), 0, size);
// after
Path file = Path.of(config.downloadDir(), name).toAbsolutePath();
if (!Files.exists(file)) {
    return Response.status(Response.Status.NOT_FOUND).build();
}
PathPart part = new PathPart(file, 0, size);
Defensive patterns

Strategy: validation

Validate before calling

if (file == null || !Files.exists(file)) {
    return Response.status(Response.Status.NOT_FOUND).build();
}

Type guard

boolean isExistingFile(Path p) {
    return p != null && Files.exists(p);
}

Try / catch

try {
    return Response.ok(new PathPart(file, 0, Files.size(file))).build();
} catch (IllegalArgumentException e) {
    return Response.status(Response.Status.NOT_FOUND).build();
}

Prevention

When it happens

Trigger: Calling `new PathPart(file, offset, count)` where `Files.exists(file)` is false — i.e. the path was deleted, never created, or the path string is misspelled/relative to the wrong working directory.

Common situations: Serving a file uploaded/produced at runtime that was cleaned up by a temp-file reaper; hardcoding a path that differs between dev and container environments; resolving a relative path against an unexpected working directory; race where the file is removed between existence check in user code and PathPart construction.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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