quarkusio/quarkus · error · IllegalArgumentException
File cannot be read: ${file}
Error message
File cannot be read: ${file} What it means
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.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/FilePart.java:38
/**
* The number of bytes to send
*/
public final long count;
/**
* Create a new partial {@link File} 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 FilePart(File file, long offset, long count) {
if (!file.exists())
throw new IllegalArgumentException("File does not exist: " + file);
if (!file.isFile())
throw new IllegalArgumentException("File is not a regular file: " + file);
if (!file.canRead())
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);
if ((offset + count) > file.length())
throw new IllegalArgumentException(
"Offset + count (" + (offset + count) + ") larger than file size (" + file.length() + "): " + file);
this.file = file;
this.offset = offset;
this.count = count;
}
}
View on GitHub (pinned to e1c734241f)
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.
Example fix
// before
new FilePart(new File("/secure/data.bin"), 0, len); // 0600 root-owned
// after
Process p = Runtime.getRuntime().exec(new String[]{"chmod", "g+r", "/secure/data.bin"});
p.waitFor();
new FilePart(new File("/secure/data.bin"), 0, len); Defensive patterns
Strategy: validation
Validate before calling
Path p = file.toPath();
if (!Files.isReadable(p)) throw new IllegalStateException("Not readable by JVM user: " + p);
Type guard
static boolean isReadableFile(File f) {
return f.canRead();
} Try / catch
try {
return new FilePart(file, offset, count);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("File cannot be read")) {
throw new IllegalStateException("Permission denied reading " + file.getAbsolutePath() + ", running as user " + System.getProperty("user.name"), e);
}
throw e;
} Prevention
- 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
When it happens
Trigger: new FilePart(file, offset, count) where file.canRead() returns false.
Common situations: 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.
Related errors
- Failed to create ${classesDir}
- Unable to determine if file '" + f + "' is a regular file
- Unable to read file '" + f + "'
- Failed to open DirectoryStream for configured certificate pa
- Failed to create the project directory: + targetDirectory
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/ab1f04f99b67938a.
Report an issue: GitHub.