MuntashirAkon/AppManager · error · IllegalArgumentException
Buffer size %,d must be at least
Error message
Buffer size %,d must be at least %s for a CharsetEncoder %s.
What it means
checkMinBufferSize() verifies the caller-provided buffer size is at least maxBytesPerChar as reported by the CharsetEncoder (minBufferSize). A smaller buffer cannot guarantee a single character always fits, so the constructor throws IllegalArgumentException with the required minimum and charset name.
Solutions
- Use the CharSequenceInputStream(CharSequence, Charset) constructor that computes a safe default buffer size.
- Query the required minimum via the library's minBufferSize logic (encoder.maxBytesPerChar()) and pass at least that value.
- Use a comfortably larger buffer (e.g. 8192) instead of tuning minimal sizes.
Example fix
// before new CharSequenceInputStream(cs, charset, 16); // after int min = (int) charset.newEncoder().maxBytesPerChar(); new CharSequenceInputStream(cs, charset, Math.max(min, 8192));
Defensive patterns
Strategy: validation
Validate before calling
float min = charset.newEncoder().maxBytesPerChar(); if (bufferSize < min) bufferSize = Math.max((int) min, 8192);
Prevention
- Use constructors without explicit bufferSize
- Recompute buffer size when changing charset
- Use standard 8KB buffers rather than minimal ones
When it happens
Trigger: Constructing CharSequenceInputStream with an explicit bufferSize smaller than minBufferSize(charsetEncoder) — e.g. a 16-byte buffer with a UTF-16 encoder whose max per-char size is larger.
Common situations: Hand-tuning tiny buffers for memory savings without checking the charset's maxBytesPerChar; switching charsets (e.g. UTF-8 to UTF-16) while keeping the same buffer size.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Bad mode
- buffersize must be bigger than 0
- count must not be negative or greater than " +…
- len(" + len + ") < 0.
- len(" + len + ") < 0.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/5ba087990043a945.
Report an issue: GitHub.
Appendix: source
Thrown at libcore/io/src/main/java/io/github/muntashirakon/io/CharSequenceInputStream.java:250
@Override
public long skip(long n) throws IOException {
//
// This could be made more efficient by using position to skip within the current buffer.
//
long skipped = 0;
while (n > 0 && available() > 0) {
read();
n--;
skipped++;
}
return skipped;
}
private static int checkMinBufferSize(final CharsetEncoder charsetEncoder, final int bufferSize) {
final float minRequired = minBufferSize(charsetEncoder);
if (bufferSize < minRequired) {
throw new IllegalArgumentException(String.format("Buffer size %,d must be at least %s for a CharsetEncoder %s.", bufferSize, minRequired,
charsetEncoder.charset().displayName()));
}
return bufferSize;
}
private static float minBufferSize(final CharsetEncoder charsetEncoder) {
return charsetEncoder.maxBytesPerChar() * 2;
}
}
View on GitHub (pinned to 0152f468fc)