{"record":{"id":"ab1f04f99b67938a","repo":"quarkusio/quarkus","slug":"file-cannot-be-read-file","errorCode":null,"errorMessage":"File cannot be read: ${file}","messagePattern":"File cannot be read: (.+?)","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":38,"sourceCode":"    /**\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":20,"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#L20-L51","documentation":"FilePart requires read access to the file it will send. If the JVM process cannot read the file (permission bits or ownership deny access), the constructor throws this IllegalArgumentException before any bytes are sent.","triggerScenarios":"new FilePart(file, offset, count) where file.canRead() returns false.","commonSituations":"Container/non-root user lacking read permission on an uploaded file written by another user; files created with restrictive umask (0600) by a different process; running in a hardened environment with SELinux/AppArmor restrictions.","solutions":["Grant read permission on the file (chmod +r) or to the JVM's user/group.","Have the producing process write the file with world/group-readable permissions.","Run the application under a user that owns or can read the file.","Copy the file to an application-writable, readable location first."],"exampleFix":"// before\nnew FilePart(new File(\"/secure/data.bin\"), 0, len); // 0600 root-owned\n// after\nProcess p = Runtime.getRuntime().exec(new String[]{\"chmod\", \"g+r\", \"/secure/data.bin\"});\np.waitFor();\nnew FilePart(new File(\"/secure/data.bin\"), 0, len);","handlingStrategy":"validation","validationCode":"Path p = file.toPath();\nif (!Files.isReadable(p)) throw new IllegalStateException(\"Not readable by JVM user: \" + p);\n","typeGuard":"static boolean isReadableFile(File f) {\n    return f.canRead();\n}","tryCatchPattern":"try {\n    return new FilePart(file, offset, count);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"File cannot be read\")) {\n        throw new IllegalStateException(\"Permission denied reading \" + file.getAbsolutePath() + \", running as user \" + System.getProperty(\"user.name\"), e);\n    }\n    throw e;\n}","preventionTips":["Check Files.isReadable before constructing parts","Ensure container/non-root users have read access to upload directories","Set permissive-enough umask in the producing process","Test file access under the same user the app runs as"],"tags":["filesystem","permissions","io"],"backgroundTag":"file-permission-denied","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}