MuntashirAkon/AppManager · error · IndexOutOfBoundsException

Array Size=" + array.length + ", offset=" + off + "…

Error message

Array Size=" + array.length + ", offset=" + off + ", length=" + len

What it means

CharSequenceInputStream.read(byte[], off, len) validates the caller-supplied array bounds and throws IndexOutOfBoundsException when off is negative, len is negative, or off+len exceeds array.length. This is a standard buffer-bounds contract guard before encoding chars into bytes.

Solutions

  1. Ensure off >= 0, len >= 0, and off + len <= array.length before calling read().
  2. Clamp len to Math.min(len, array.length - off) when reading at a nonzero offset.
  3. Use the stream's single-argument read() or readAllBytes-style helpers to avoid manual offset math.

Example fix

// before
int n = stream.read(buf, off, buf.length);
// after
int n = stream.read(buf, off, Math.min(buf.length - off, buf.length));
Defensive patterns

Strategy: validation

Validate before calling

static boolean readableRange(byte[] a, int off, int len) {
    return a != null && off >= 0 && len >= 0 && off + len <= a.length;
}

Try / catch

if (!readableRange(buf, off, len)) throw new IllegalArgumentException("bad off/len");
int n = stream.read(buf, off, len);

Prevention

When it happens

Trigger: Calling read(array, off, len) with off + len > array.length, or negative off/len. The SOURCE shows the check `if (len < 0 || off + len > array.length)`.

Common situations: Misreading the API as (offset, count-of-remaining) and passing len = array.length while off > 0; arithmetic errors computing remaining bytes; passing a zero-length buffer with nonzero off.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/92082acd14e856de. Report an issue: GitHub.

Appendix: source

Thrown at libcore/io/src/main/java/io/github/muntashirakon/io/CharSequenceInputStream.java:171

                return mByteBuffer.get() & 0xFF;
            }
            fillBuffer();
            if (!mByteBuffer.hasRemaining() && !mCharBuffer.hasRemaining()) {
                return EOF;
            }
        }
    }

    @Override
    public int read(final byte[] b) throws IOException {
        return read(b, 0, b.length);
    }

    @Override
    public int read(final byte[] array, int off, int len) throws IOException {
        Objects.requireNonNull(array, "array");
        if (len < 0 || off + len > array.length) {
            throw new IndexOutOfBoundsException("Array Size=" + array.length + ", offset=" + off + ", length=" + len);
        }
        if (len == 0) {
            return 0; // must return 0 for zero length read
        }
        if (!mByteBuffer.hasRemaining() && !mCharBuffer.hasRemaining()) {
            return EOF;
        }
        int bytesRead = 0;
        while (len > 0) {
            if (mByteBuffer.hasRemaining()) {
                final int chunk = Math.min(mByteBuffer.remaining(), len);
                mByteBuffer.get(array, off, chunk);
                off += chunk;
                len -= chunk;
                bytesRead += chunk;
            } else {
                fillBuffer();
                if (!mByteBuffer.hasRemaining() && !mCharBuffer.hasRemaining()) {

View on GitHub (pinned to 0152f468fc)