ReactiveX/RxJava · error · IllegalArgumentException

Array of size 8 expected but got {}

Error message

Array of size 8 expected but got {}

What it means

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

Source

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

        @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]);
            }
        }

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

        @SuppressWarnings("unchecked")
            @Override
            public R apply(Object[] a) throws Throwable {
                if (a.length != 9) {
                    throw new IllegalArgumentException("Array of size 9 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], (T9) a[8]);
            }
        }

View on GitHub (pinned to a8ab535614)

Solutions

  1. Pass exactly 8 elements to the 8-arity adapter; correct the array builder.
  2. Prefer public 8-source zip/combineLatest overloads.
  3. Add a length-8 input test.
  4. Drive array length from the actual source count.

Example fix

// before
Function<Object[], R> f = Functions.array8Func(fn8);
R r = f.apply(arr7); // length 7 -> throws

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

Strategy: validation

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: An 8-arity adapter receives an Object[] of length != 8. An internal/custom-operator wiring error; rarely hit from normal public API use.

Common situations: Variable-length source list fed to a fixed 8-arity adapter; fan-in refactoring that changed source count but not the array; reflective payload construction.

Related errors


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