juicedata/juicefs · error · IllegalArgumentException

arguments: " + off + " " + len

Error message

arguments: " + off + " " + len

What it means

The positioned read read(long pos, byte[] b, int off, int len) throws IllegalArgumentException("arguments: off len") when b is null, off < 0, len < 0, or b.length - off < len. These mirror the java.io APIs' preconditions: the requested range must fit inside the caller-supplied buffer. The message includes the offending off and len values.

Source

Thrown at sdk/java/src/main/java/io/juicefs/JuiceFileSystemImpl.java:1134

    }

    private boolean refill() throws IOException {
      buf.clear();
      int read = read(position, buf);
      if (read <= 0) {
        buf.limit(0);
        return false; // EOF
      }
      buf.position(0);
      buf.limit(read);
      position += read;
      return true;
    }

    @Override
    public synchronized int read(long pos, byte[] b, int off, int len) throws IOException {
      if (b == null || off < 0 || len < 0 || b.length - off < len) {
        throw new IllegalArgumentException("arguments: " + off + " " + len);
      }
      int got = read(pos, ByteBuffer.wrap(b, off, len));
      statistics.incrementBytesRead(got);
      return got;
    }

    @Override
    public synchronized int read(ByteBuffer b) throws IOException {
      if (!b.hasRemaining())
        return 0;
      if (buf == null)
        throw new IOException("stream was closed");
      if (!buf.hasRemaining() && b.remaining() <= buf.capacity() && !refill()) {
        return -1;
      }
      ByteBuffer srcBuf = buf.duplicate();
      int got = Math.min(b.remaining(), srcBuf.remaining());
      if (got > 0) {

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Validate before calling: assert off >= 0, len >= 0, and off + len <= b.length.
  2. Pass b.length-derived values: use off=0, len=b.length for full-buffer reads.
  3. Fix swapped parameters if off and len are transposed at the call site.

Example fix

// before
in.read(pos, buf, off, bufSize); // buf may be smaller than bufSize
// after
long n = Math.min(bufSize, buf.length - off);
in.read(pos, buf, off, (int) n);
Defensive patterns

Strategy: validation

Validate before calling

if (b == null || off < 0 || len < 0 || b.length - off < len) {
  throw new IllegalArgumentException("bad read args off=" + off + " len=" + len + " buf=" + (b == null ? "null" : b.length));
}
int got = in.read(pos, b, off, len);

Prevention

When it happens

Trigger: Calling in.read(pos, b, off, len) with a null buffer, negative off/len, or a (off + len) pair exceeding b.length — commonly a len computed as bufferCapacity while the actual array is smaller, or off/len swapped.

Common situations: Preallocated-buffer pooling code passing a capacity constant instead of the array's real length; off-by-one on off; reading with a length derived from metadata larger than the allocated buffer.

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


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/3632b86aeb316216. Report an issue: GitHub.