ReactiveX/RxJava · error · IllegalArgumentException

Array of size 7 expected but got {}

Error message

Array of size 7 expected but got {}

What it means

Thrown by Array7Func.apply(Object[]) when the array length is not exactly 7. Array7Func is a record adapting Function7 to Function<Object[],R>, backing 7-way zip/combineLatest. Array arity must equal 7.

Source

Thrown at src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java:536

        @SuppressWarnings("unchecked")
            @Override
            public R apply(Object[] a) throws Throwable {
                if (a.length != 6) {
                    throw new IllegalArgumentException("Array of size 6 expected but got " + a.length);
                }
                return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5]);
            }
        }

    record Array7Func<T1, T2, T3, T4, T5, T6, T7, R>(
            Function7<T1, T2, T3, T4, T5, T6, T7, R> f) implements Function<Object[], R> {

        @SuppressWarnings("unchecked")
            @Override
            public R apply(Object[] a) throws Throwable {
                if (a.length != 7) {
                    throw new IllegalArgumentException("Array of size 7 expected but got " + a.length);
                }
                return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5], (T7) a[6]);
            }
        }

    record Array8Func<T1, T2, T3, T4, T5, T6, T7, T8, R>(
            Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> f) implements Function<Object[], R> {

        @SuppressWarnings("unchecked")
            @Override
            public R apply(Object[] a) throws Throwable {
                if (a.length != 8) {
                    throw new IllegalArgumentException("Array of size 8 expected but got " + a.length);
                }
                return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5], (T7) a[6], (T8) a[7]);
            }
        }

View on GitHub (pinned to a8ab535614)

Solutions

  1. Provide exactly 7 elements to the 7-arity adapter; fix the array construction.
  2. Use the public 7-source zip/combineLatest APIs.
  3. Add a length-7 input test.
  4. Bind array length to the source count, not a constant.

Example fix

// before
Function<Object[], R> f = Functions.array7Func(fn7);
R r = f.apply(arr6); // length 6 -> throws

// after
Function<Object[], R> f = Functions.array7Func(fn7);
R r = f.apply(new Object[]{ a, b, c, d, e, f2, g }); // length 7 matches arity
Defensive patterns

Strategy: validation

Validate before calling

assert args.length == 7 : "7-arity adapter requires length-7 array";

Try / catch

try {
    R r = array7Fn.apply(args);
} catch (IllegalArgumentException e) {
    // array length != 7
}

Prevention

When it happens

Trigger: A 7-arity adapter receives an Object[] of length != 7. Reachable from custom operator/test code that mismatches source count and adapter arity.

Common situations: Dynamic source list fed to a fixed 7-arity adapter; refactoring a fan-in without realigning the array; reflective array assembly with the wrong count.

Related errors


AI-assisted analysis of ReactiveX/RxJava@a8ab535614 (2026-08-13). Data as JSON: /api/errors/31e6add7a3162a88. Report an issue: GitHub.