{"record":{"id":"30229cc7a0232415","repo":"quarkusio/quarkus","slug":"file-does-not-exist-file-30229c","errorCode":null,"errorMessage":"File does not exist: ${file}","messagePattern":"File does not exist: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/PathPart.java","lineNumber":37,"sourceCode":"     * The starting byte of the file\n     */\n    public final long offset;\n\n    /**\n     * The number of bytes to send\n     */\n    public final long count;\n\n    /**\n     * Create a new partial {@link Path} object.\n     *\n     * @param file The file to send\n     * @param offset The starting byte of the file (must be >= 0)\n     * @param count The number of bytes to send (must be >= 0 and offset+count <= file size)\n     */\n    public PathPart(Path file, long offset, long count) {\n        if (!Files.exists(file))\n            throw new IllegalArgumentException(\"File does not exist: \" + file);\n        if (!Files.isRegularFile(file))\n            throw new IllegalArgumentException(\"File is not a regular file: \" + file);\n        if (!Files.isReadable(file))\n            throw new IllegalArgumentException(\"File cannot be read: \" + file);\n        if (offset < 0)\n            throw new IllegalArgumentException(\"Offset (\" + offset + \") must be >= 0: \" + file);\n        if (count < 0)\n            throw new IllegalArgumentException(\"Count (\" + count + \") must be >= 0: \" + file);\n        long fileLength;\n        try {\n            fileLength = Files.size(file);\n            if ((offset + count) > fileLength)\n                throw new IllegalArgumentException(\n                        \"Offset + count (\" + (offset + count) + \") larger than file size (\" + fileLength + \"): \" + file);\n        } catch (IOException e) {\n            throw new UncheckedIOException(e);\n        }\n        this.file = file;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/PathPart.java#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the exact path exists with `Files.exists(file)` (and log `file.toAbsolutePath()`) before constructing PathPart.","Fix path resolution: use absolute paths or resolve relative paths against a known base directory.","Check that any step that creates the file actually ran (e.g. the upload/export step), and check for cleanup jobs deleting the file.","Handle the IllegalArgumentException in the endpoint and return 404 instead of an error response."],"exampleFix":"// before\nPathPart part = new PathPart(Path.of(config.downloadDir(), name), 0, size);\n// after\nPath file = Path.of(config.downloadDir(), name).toAbsolutePath();\nif (!Files.exists(file)) {\n    return Response.status(Response.Status.NOT_FOUND).build();\n}\nPathPart part = new PathPart(file, 0, size);","handlingStrategy":"validation","validationCode":"if (file == null || !Files.exists(file)) {\n    return Response.status(Response.Status.NOT_FOUND).build();\n}","typeGuard":"boolean isExistingFile(Path p) {\n    return p != null && Files.exists(p);\n}","tryCatchPattern":"try {\n    return Response.ok(new PathPart(file, 0, Files.size(file))).build();\n} catch (IllegalArgumentException e) {\n    return Response.status(Response.Status.NOT_FOUND).build();\n}","preventionTips":["Log file.toAbsolutePath() in errors to reveal working-directory/relative-path mistakes.","Construct PathPart as late as possible, right before responding, to minimize deletion races.","Validate uploaded/produced files exist before registering them for download."],"tags":["filesystem","illegal-argument","resteasy-reactive","file-serving"],"backgroundTag":"file-not-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}