{"record":{"id":"b28f5c098e60648b","repo":"quarkusio/quarkus","slug":"file-is-not-a-regular-file-file","errorCode":null,"errorMessage":"File is not a regular file: ${file}","messagePattern":"File is not a regular file: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/FilePart.java","lineNumber":36,"sourceCode":"    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 File} 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 FilePart(File file, long offset, long count) {\n        if (!file.exists())\n            throw new IllegalArgumentException(\"File does not exist: \" + file);\n        if (!file.isFile())\n            throw new IllegalArgumentException(\"File is not a regular file: \" + file);\n        if (!file.canRead())\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        if ((offset + count) > file.length())\n            throw new IllegalArgumentException(\n                    \"Offset + count (\" + (offset + count) + \") larger than file size (\" + file.length() + \"): \" + file);\n        this.file = file;\n        this.offset = offset;\n        this.count = count;\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":51,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/FilePart.java#L18-L51","documentation":"FilePart can only send byte ranges of regular files. The constructor rejects anything that exists but is not a regular file (directories, named pipes, special device files) with this IllegalArgumentException.","triggerScenarios":"new FilePart(file, offset, count) where file.exists() is true but file.isFile() is false — e.g. a File pointing at a directory or a FIFO/socket.","commonSituations":"Passing a directory because a path variable was meant to point to a file; user-supplied upload path pointing at a directory; platform special files (e.g. /dev entries) used as data sources.","solutions":["Point the FilePart at the actual file inside the directory rather than the directory itself.","Validate with Files.isRegularFile(Path) before constructing the part.","If streaming non-regular sources, use a stream/byte-array based part type instead of FilePart."],"exampleFix":"// before\nnew FilePart(new File(requestDir), 0, count);\n// after\nnew FilePart(new File(requestDir, \"payload.bin\"), 0, count);","handlingStrategy":"validation","validationCode":"Path p = Paths.get(path);\nif (!Files.isRegularFile(p)) throw new IllegalStateException(\"Not a regular file: \" + p);","typeGuard":"static boolean isRegularFile(File f) {\n    return f != null && f.isFile();\n}","tryCatchPattern":"try {\n    return new FilePart(file, offset, count);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"File is not a regular file\")) {\n        throw new IllegalArgumentException(\"Expected a file, got directory/special file: \" + file, e);\n    }\n    throw e;\n}","preventionTips":["Validate with Files.isRegularFile before constructing parts","Resolve directories to concrete file names before sending","Sanitize user-supplied paths that may point at directories"],"tags":["filesystem","io","argument-validation"],"backgroundTag":"not-a-regular-file","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"}