apache/flink · error · IllegalArgumentException

bytes cannot be null.

Error message

bytes cannot be null.

What it means

Plain IllegalArgumentException from NoFetchingInput.read(byte[], int, int) when the destination array is null. This is a programmer-contract violation inside a Kryo read path, not an environmental failure.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/runtime/NoFetchingInput.java:114

        do {
            // Logical change 2 (from Kryo Input.require): "capacity - remaining" -> "required -
            // remaining"
            count = fill(buffer, remaining, required - remaining);
            if (count == -1) {
                throw new KryoBufferUnderflowException("Buffer underflow.");
            }
            remaining += count;
        } while (remaining < required);

        limit = remaining;
        return remaining;
    }

    @Override
    public int read(byte[] bytes, int offset, int count) throws KryoException {
        if (bytes == null) {
            throw new IllegalArgumentException("bytes cannot be null.");
        }

        try {
            return inputStream.read(bytes, offset, count);
        } catch (IOException ex) {
            throw new KryoException(ex);
        }
    }

    @Override
    public void skip(int count) throws KryoException {
        try {
            inputStream.skip(count);
        } catch (IOException ex) {
            throw new KryoException(ex);
        }
    }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Allocate the destination byte[] before calling read (size = the count you will read)
  2. Add a null check/Objects.requireNonNull in the custom serializer for early failure

Example fix

// before
byte[] buf;
input.read(buf, 0, len);

// after
byte[] buf = new byte[len];
input.read(buf, 0, len);
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(bytes, "bytes");
input.read(bytes, offset, count);

Prevention

When it happens

Trigger: A Kryo Serializer or Kryo internals calling input.read(bytes, offset, count) with a null byte array while deserializing through Flink's NoFetchingInput.

Common situations: Custom Kryo serializer passes an uninitialized buffer (e.g. lazy field not yet allocated) to read(); copy-pasted serializer code with a null target array on a conditional branch.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/be2dbae1591cf90d. Report an issue: GitHub.