nostra13/Android-Universal-Image-Loader · error · IllegalArgumentException

Unsupported encoding

Error message

Unsupported encoding

What it means

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.

Source

Thrown at library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/StrictLineReader.java:93

	 * Constructs a new {@code LineReader} with the specified capacity and charset.
	 *
	 * @param in the {@code InputStream} to read data from.
	 * @param capacity the capacity of the buffer.
	 * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
	 * supported.
	 * @throws NullPointerException if {@code in} or {@code charset} is null.
	 * @throws IllegalArgumentException if {@code capacity} is negative or zero
	 * or the specified charset is not supported.
	 */
	public StrictLineReader(InputStream in, int capacity, Charset charset) {
		if (in == null || charset == null) {
			throw new NullPointerException();
		}
		if (capacity < 0) {
			throw new IllegalArgumentException("capacity <= 0");
		}
		if (!(charset.equals(Util.US_ASCII))) {
			throw new IllegalArgumentException("Unsupported encoding");
		}

		this.in = in;
		this.charset = charset;
		buf = new byte[capacity];
	}

	/**
	 * Closes the reader by closing the underlying {@code InputStream} and
	 * marking this reader as closed.
	 *
	 * @throws IOException for errors when closing the underlying {@code InputStream}.
	 */
	public void close() throws IOException {
		synchronized (in) {
			if (buf != null) {
				buf = null;
				in.close();

View on GitHub (pinned to ba33ec64d0)

Solutions

  1. Pass Util.US_ASCII; the journal format and this implementation require it.
  2. For non-ASCII input use BufferedReader with an InputStreamReader instead.
  3. If you fork StrictLineReader for multi-charset use, port the full OkHttp decoding logic rather than expecting the flag to lift.

Example fix

// before
new StrictLineReader(in, 8192, StandardCharsets.UTF_8); // IllegalArgumentException

// after
new StrictLineReader(in, 8192, Util.US_ASCII);
Defensive patterns

Strategy: validation

Validate before calling

Charset cs = Util.US_ASCII; // the only supported charset
new StrictLineReader(in, 8192, cs);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nostra13/Android-Universal-Image-Loader@ba33ec64d0 (2026-08-14). Data as JSON: /api/errors/d63186b717443877. Report an issue: GitHub.