{"record":{"id":"417eecf4ab770c2e","repo":"nostra13/Android-Universal-Image-Loader","slug":"capacity-0","errorCode":null,"errorMessage":"capacity <= 0","messagePattern":"capacity <= 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/StrictLineReader.java","lineNumber":90,"sourceCode":"\t}\n\n\t/**\n\t * Constructs a new {@code LineReader} with the specified capacity and charset.\n\t *\n\t * @param in the {@code InputStream} to read data from.\n\t * @param capacity the capacity of the buffer.\n\t * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are\n\t * supported.\n\t * @throws NullPointerException if {@code in} or {@code charset} is null.\n\t * @throws IllegalArgumentException if {@code capacity} is negative or zero\n\t * or the specified charset is not supported.\n\t */\n\tpublic StrictLineReader(InputStream in, int capacity, Charset charset) {\n\t\tif (in == null || charset == null) {\n\t\t\tthrow new NullPointerException();\n\t\t}\n\t\tif (capacity < 0) {\n\t\t\tthrow new IllegalArgumentException(\"capacity <= 0\");\n\t\t}\n\t\tif (!(charset.equals(Util.US_ASCII))) {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported encoding\");\n\t\t}\n\n\t\tthis.in = in;\n\t\tthis.charset = charset;\n\t\tbuf = new byte[capacity];\n\t}\n\n\t/**\n\t * Closes the reader by closing the underlying {@code InputStream} and\n\t * marking this reader as closed.\n\t *\n\t * @throws IOException for errors when closing the underlying {@code InputStream}.\n\t */\n\tpublic void close() throws IOException {\n\t\tsynchronized (in) {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/StrictLineReader.java#L72-L108","documentation":"StrictLineReader's constructor throws IllegalArgumentException when capacity is negative (message text says 'capacity <= 0', and the javadoc says negative or zero, but the actual check is capacity < 0 — zero is accepted and merely allocates an empty buffer). StrictLineReader is the journal parser used inside DiskLruCache, so externally you normally never construct it yourself.","triggerScenarios":"Direct construction new StrictLineReader(in, negativeCapacity, Util.US_ASCII). In-library usage passes a fixed positive buffer size, so this only fires from custom code reusing this utility class.","commonSituations":"Copying the ext StrictLineReader utility into other projects and feeding it a computed buffer size that can be negative (e.g. size - header overhead underflowing); passing a constant of -1 as an 'unspecified' sentinel.","solutions":["Pass a positive buffer capacity, e.g. 8192.","Clamp computed capacities: Math.max(1, computed).","Prefer BufferedReader for general-purpose line reading; StrictLineReader is purpose-built for the DiskLruCache journal."],"exampleFix":"// before\nnew StrictLineReader(in, remaining - headerLen, Util.US_ASCII); // negative when file too short\n\n// after\nnew StrictLineReader(in, Math.max(1, remaining - headerLen), Util.US_ASCII);","handlingStrategy":"validation","validationCode":"int capacityArg = Math.max(1, capacity);\nnew StrictLineReader(in, capacityArg, Util.US_ASCII);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a fixed positive constant (e.g. 8192) unless profiling says otherwise.","Clamp any computed capacity before constructing.","Note the check is capacity < 0; the message 'capacity <= 0' is misleading — zero is accepted."],"tags":["io","validation","utility","journal","constructor"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}