{"record":{"id":"d63186b717443877","repo":"nostra13/Android-Universal-Image-Loader","slug":"unsupported-encoding","errorCode":null,"errorMessage":"Unsupported encoding","messagePattern":"Unsupported encoding","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/StrictLineReader.java","lineNumber":93,"sourceCode":"\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) {\n\t\t\tif (buf != null) {\n\t\t\t\tbuf = null;\n\t\t\t\tin.close();","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/nostra13/Android-Universal-Image-Loader/blob/ba33ec64d0daaa881d35852460e78c58d086bc18/library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/StrictLineReader.java#L75-L111","documentation":"StrictLineReader's constructor throws IllegalArgumentException for any charset other than US-ASCII. This reader does manual single-byte line decoding and only supports US-ASCII (the DiskLruCache journal format is ASCII by design); UTF-8 and ISO-8859-1 are mentioned in the javadoc but rejected by this implementation's strict charset.equals check.","triggerScenarios":"Constructing new StrictLineReader(in, capacity, Charsets.UTF_8) or StandardCharsets.UTF_8 / ISO-8859-1. The only supported call is with Util.US_ASCII, which is what DiskLruCache uses internally.","commonSituations":"Reusing the vendored StrictLineReader class in other code with UTF-8 text files; porting the OkHttp-derived version (which supports UTF-8/ISO-8859-1) and assuming this stripped-down copy behaves the same.","solutions":["Pass Util.US_ASCII; the journal format and this implementation require it.","For non-ASCII input use BufferedReader with an InputStreamReader instead.","If you fork StrictLineReader for multi-charset use, port the full OkHttp decoding logic rather than expecting the flag to lift."],"exampleFix":"// before\nnew StrictLineReader(in, 8192, StandardCharsets.UTF_8); // IllegalArgumentException\n\n// after\nnew StrictLineReader(in, 8192, Util.US_ASCII);","handlingStrategy":"validation","validationCode":"Charset cs = Util.US_ASCII; // the only supported charset\nnew StrictLineReader(in, 8192, cs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["This vendored StrictLineReader is ASCII-only despite its javadoc mentioning UTF-8/ISO-8859-1.","Use BufferedReader/InputStreamReader for non-ASCII text instead of this class.","If porting from OkHttp's version, re-check which behaviors were stripped."],"tags":["io","validation","charset","utility","journal"],"backgroundTag":null,"analyzedSha":"ba33ec64d0daaa881d35852460e78c58d086bc18","analyzedAt":"2026-08-14T15:41:15.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}