{"record":{"id":"b00be8485bcb1e9a","repo":"quarkusio/quarkus","slug":"count-count-must-be-0-file-b00be8","errorCode":null,"errorMessage":"Count (${count}) must be >= 0: ${file}","messagePattern":"Count \\((.+?)\\) must be >= 0: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/PathPart.java","lineNumber":45,"sourceCode":"\n    /**\n     * Create a new partial {@link Path} 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 PathPart(Path file, long offset, long count) {\n        if (!Files.exists(file))\n            throw new IllegalArgumentException(\"File does not exist: \" + file);\n        if (!Files.isRegularFile(file))\n            throw new IllegalArgumentException(\"File is not a regular file: \" + file);\n        if (!Files.isReadable(file))\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        long fileLength;\n        try {\n            fileLength = Files.size(file);\n            if ((offset + count) > fileLength)\n                throw new IllegalArgumentException(\n                        \"Offset + count (\" + (offset + count) + \") larger than file size (\" + fileLength + \"): \" + file);\n        } catch (IOException e) {\n            throw new UncheckedIOException(e);\n        }\n        this.file = file;\n        this.offset = offset;\n        this.count = count;\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":60,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/PathPart.java#L27-L60","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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."],"exampleFix":"// before\nPathPart part = new PathPart(file, start, -1); // 'until end'\n// after\nlong fileSize = Files.size(file);\nlong count = fileSize - start;\nPathPart part = new PathPart(file, start, count);","handlingStrategy":"validation","validationCode":"long fileSize = Files.size(file);\nif (offset < 0 || end < offset || end >= fileSize) {\n    return Response.status(Response.Status.REQUESTED_RANGE_NOT_SATISFIABLE).build();\n}\nlong count = end - offset + 1;","typeGuard":"boolean isValidRange(long offset, long count) {\n    return offset >= 0 && count >= 0;\n}","tryCatchPattern":"try {\n    return Response.ok(new PathPart(file, offset, count)).build();\n} catch (IllegalArgumentException e) {\n    return Response.status(Response.Status.REQUESTED_RANGE_NOT_SATISFIABLE).build();\n}","preventionTips":["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."],"tags":["illegal-argument","validation","resteasy-reactive","range-request"],"backgroundTag":"invalid-range-request","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"}