ReactiveX/RxJava · error · IllegalArgumentException

Array of size 9 expected but got {a.length}

Error message

Array of size 9 expected but got {a.length}

What it means

Thrown by Array9Func.apply(Object[]) when the array length is not exactly 9. Array9Func is a record adapting Function9 (the highest fixed arity) to Function<Object[],R>, backing 9-way zip/combineLatest. Array arity must equal 9. Note: this is the last fixed-arity adapter (Function10+ use vararg/function-array paths).

Source

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

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

    static final class Identity implements Function<Object, Object> {
        @Override
        public Object apply(Object v) {
            return v;
        }

        @Override
        public String toString() {
            return "IdentityFunction";
        }
    }

    static final class EmptyRunnable implements Runnable {

View on GitHub (pinned to a8ab535614)

Solutions

  1. Pass exactly 9 elements to the 9-arity adapter; fix the array-building code.
  2. Use the public 9-source zip/combineLatest overloads that manage arity internally.
  3. Add a length-9 input test.
  4. If you need 10+ sources, switch to the vararg/function-list zip overload instead of a fixed-arity adapter.

Example fix

// before
Function<Object[], R> f = Functions.array9Func(fn9);
R r = f.apply(arr8); // length 8 -> throws

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

Strategy: validation

Validate before calling

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

Try / catch

try {
    R r = array9Fn.apply(args);
} catch (IllegalArgumentException e) {
    // array length != 9; or switch to vararg zip if you need >= 10 sources
}

Prevention

When it happens

Trigger: A 9-arity adapter receives an Object[] of length != 9. Custom-operator or test wiring error; not reachable from typical application code using public zip/combineLatest APIs.

Common situations: Dynamic source list fed to a fixed 9-arity adapter; refactoring a 9-way combine without updating array assembly; reflective construction with wrong count; bumping a 9-source combine to 10 sources but keeping the Function9 adapter.

Related errors


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