quarkusio/quarkus · error · IllegalArgumentException
Count (${count}) must be >= 0: ${file}
Error message
Count (${count}) must be >= 0: ${file} What it means
IllegalArgumentException from the PathPart constructor: a partial-path response was requested with a negative byte count. The same existence/readability/offset/count validation as FilePart applies; the count argument is the value at fault.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/PathPart.java:45
/**
* Create a new partial {@link Path} 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 PathPart(Path file, long offset, long count) {
if (!Files.exists(file))
throw new IllegalArgumentException("File does not exist: " + file);
if (!Files.isRegularFile(file))
throw new IllegalArgumentException("File is not a regular file: " + file);
if (!Files.isReadable(file))
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);
long fileLength;
try {
fileLength = Files.size(file);
if ((offset + count) > fileLength)
throw new IllegalArgumentException(
"Offset + count (" + (offset + count) + ") larger than file size (" + fileLength + "): " + file);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
this.file = file;
this.offset = offset;
this.count = count;
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Compute count as `Math.max(0, end - start)` or validate `end >= start` before construction.
- For 'rest of file' semantics, read the file size with `Files.size(file)` and compute `count = fileSize - offset` instead of using -1.
- Return 416 Range Not Satisfiable when the parsed range is invalid rather than constructing the part.
Example fix
// before PathPart part = new PathPart(file, start, -1); // 'until end' // after long fileSize = Files.size(file); long count = fileSize - start; PathPart part = new PathPart(file, start, count);
Defensive patterns
Strategy: validation
Validate before calling
long fileSize = Files.size(file);
if (offset < 0 || end < offset || end >= fileSize) {
return Response.status(Response.Status.REQUESTED_RANGE_NOT_SATISFIABLE).build();
}
long count = end - offset + 1; Type guard
boolean isValidRange(long offset, long count) {
return offset >= 0 && count >= 0;
} Try / catch
try {
return Response.ok(new PathPart(file, offset, count)).build();
} catch (IllegalArgumentException e) {
return Response.status(Response.Status.REQUESTED_RANGE_NOT_SATISFIABLE).build();
} Prevention
- Derive count from validated start/end indices rather than trusting raw client numbers.
- Compute count as Math.max(0, end - start) as a final guard.
- Write unit tests for Range parsing with start > end, missing bounds, and suffix ranges.
When it happens
Trigger: Calling `new PathPart(file, offset, count)` with a negative count, usually from computing `end - start` where end < start, or passing -1 as 'until end of file'.
Common situations: Range header parsing where the client sends `bytes=500-100` (start > end); using -1 as an 'unbounded' convention; off-by-one in end index computation.
Related errors
- Offset (${offset}) must be >= 0: ${file}
- Offset + count (${offset + count}) larger than file size (${
- An attachment must contain either a file or a raw data
- seconds cannot be negative
- seconds cannot be negative
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/b00be8485bcb1e9a.
Report an issue: GitHub.