quarkusio/quarkus · error · IllegalArgumentException
File does not exist: ${file}
Error message
File does not exist: ${file} What it means
The FilePart(File, long, long) constructor validates its File argument before creating the part used to send a byte range of a file. If the file does not exist on the filesystem, an IllegalArgumentException is thrown immediately instead of failing later during the send.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/FilePart.java:34
* 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 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
- Verify the path is correct and resolve it against the intended base directory.
- Create the file before constructing the FilePart (or use Files.createFile/absolute paths).
- Check existence with Files.exists(Path) and fail fast with a clear application-level error.
Example fix
// before
return new FilePart(new File(config.path), 0, size);
// after
File f = new File(config.path);
if (!f.exists()) throw new IllegalStateException("Missing upload file: " + f.getAbsolutePath());
return new FilePart(f, 0, size); Defensive patterns
Strategy: validation
Validate before calling
File f = new File(path);
if (!f.exists()) throw new IllegalStateException("File missing: " + f.getAbsolutePath());
// safe to construct now
FilePart part = new FilePart(f, offset, count); Type guard
static boolean isSendableFile(File f) {
return f != null && f.exists() && f.isFile() && f.canRead();
} Try / catch
try {
return new FilePart(file, offset, count);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("File does not exist")) {
throw new IllegalStateException("Upload file missing: " + file.getAbsolutePath(), e);
}
throw e;
} Prevention
- Always log file.getAbsolutePath() to reveal wrong working directories
- Check Files.exists before constructing parts
- Avoid relative paths derived from assumptions about CWD
When it happens
Trigger: new FilePart(file, offset, count) where file.exists() returns false (typical first check in the validation chain).
Common situations: Typo or wrong relative path resolved against a different working directory; file deleted between path computation and FilePart construction; packaging a resource that was never written to disk.
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
- File is not a regular file: ${file}
- Failed to create output directory for generated sources: %s
- IOException (wrapped)
- Unable to validate the application root for remote-dev path:
- Unable to validate remote-dev path: <file>
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/c580e23ea27ed98a.
Report an issue: GitHub.