ReactiveX/RxJava · error · IllegalArgumentException
Array of size 6 expected but got {}
Error message
Array of size 6 expected but got {} What it means
Thrown by Array6Func.apply(Object[]) when the array length is not exactly 6. Array6Func is a record adapting Function6 to Function<Object[],R>, backing 6-way zip/combineLatest fan-in. Array arity must equal 6.
Source
Thrown at src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java:523
@SuppressWarnings("unchecked")
@Override
public R apply(Object[] a) throws Throwable {
if (a.length != 5) {
throw new IllegalArgumentException("Array of size 5 expected but got " + a.length);
}
return f.apply((T1)a[0], (T2)a[1], (T3)a[2], (T4)a[3], (T5)a[4]);
}
}
record Array6Func<T1, T2, T3, T4, T5, T6, R>(
Function6<T1, T2, T3, T4, T5, T6, R> f) implements Function<Object[], R> {
@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]);
}
}
View on GitHub (pinned to a8ab535614)
Solutions
- Pass exactly 6 elements to the 6-arity adapter; correct the array-building code.
- Prefer public 6-source zip/combineLatest overloads that manage arity.
- Add a test verifying length-6 input.
- Couple array length to the live source count.
Example fix
// before
Function<Object[], R> f = Functions.array6Func(fn6);
R r = f.apply(arr5); // length 5 -> throws
// after
Function<Object[], R> f = Functions.array6Func(fn6);
R r = f.apply(new Object[]{ a, b, c, d, e, f2 }); // length 6 matches arity Defensive patterns
Strategy: validation
Validate before calling
assert args.length == 6 : "6-arity adapter requires length-6 array";
Try / catch
try {
R r = array6Fn.apply(args);
} catch (IllegalArgumentException e) {
// array length != 6
} Prevention
- Prefer public 6-source zip/combineLatest APIs.
- Derive array length from the source count.
- Add a length-6 input test.
When it happens
Trigger: A 6-arity adapter receives an Object[] of length != 6. An internal/custom-operator wiring error rather than typical application usage.
Common situations: Variable-length source list fed to a fixed 6-arity adapter; refactoring a multi-source combine without updating the array assembly; reflective construction of the payload array.
Related errors
- Array of size 2 expected but got {}
- Array of size 3 expected but got {}
- Array of size 4 expected but got {}
- Array of size 5 expected but got {}
- Array of size 7 expected but got {}
AI-assisted analysis of ReactiveX/RxJava@a8ab535614 (2026-08-13).
Data as JSON: /api/errors/edc77621c3652c7b.
Report an issue: GitHub.