{"record":{"id":"6147f86457feca0d","repo":"ReactiveX/RxJava","slug":"array-of-size-4-expected-but-got","errorCode":null,"errorMessage":"Array of size 4 expected but got {}","messagePattern":"Array of size 4 expected but got (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java","lineNumber":493,"sourceCode":"    record Array3Func<T1, T2, T3, R>(Function3<T1, T2, T3, R> f) implements Function<Object[], R> {\n\n        @SuppressWarnings(\"unchecked\")\n            @Override\n            public R apply(Object[] a) throws Throwable {\n                if (a.length != 3) {\n                    throw new IllegalArgumentException(\"Array of size 3 expected but got \" + a.length);\n                }\n                return f.apply((T1) a[0], (T2) a[1], (T3) a[2]);\n            }\n        }\n\n    record Array4Func<T1, T2, T3, T4, R>(Function4<T1, T2, T3, T4, R> f) implements Function<Object[], R> {\n\n        @SuppressWarnings(\"unchecked\")\n            @Override\n            public R apply(Object[] a) throws Throwable {\n                if (a.length != 4) {\n                    throw new IllegalArgumentException(\"Array of size 4 expected but got \" + a.length);\n                }\n                return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3]);\n            }\n        }\n\n    static final class Array5Func<T1, T2, T3, T4, T5, R> implements Function<Object[], R> {\n        private final Function5<T1, T2, T3, T4, T5, R> f;\n\n        Array5Func(Function5<T1, T2, T3, T4, T5, R> f) {\n            this.f = f;\n        }\n\n        @SuppressWarnings(\"unchecked\")\n        @Override\n        public R apply(Object[] a) throws Throwable {\n            if (a.length != 5) {\n                throw new IllegalArgumentException(\"Array of size 5 expected but got \" + a.length);\n            }","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java#L475-L511","documentation":"Thrown by Array4Func.apply(Object[]) when the array length is not exactly 4. Array4Func adapts a Function4 (4-ary) to Function<Object[],R>, backing 4-way zip/combineLatest fan-in. The array arity must equal the number of combined sources.","triggerScenarios":"A 4-arity adapter receives an Object[] whose length != 4, almost always an internal/custom-operator wiring mistake rather than normal application usage.","commonSituations":"Manually constructing a 4-source fan-in with an array built from a list of indeterminate size; mismatching the adapter arity with the number of sources after refactoring; reflective/dynamic source composition.","solutions":["Pass exactly 4 elements in the array to a 4-arity adapter; correct the array-building code.","Prefer the public 4-source zip/combineLatest APIs which guarantee correct arity.","Add a unit test verifying length-4 input at the adapter call site.","Keep array length coupled to the source list size to avoid drift."],"exampleFix":"// before\nFunction<Object[], R> f = Functions.array4Func(fn4);\nR r = f.apply(new Object[]{ a, b, c }); // length 3 -> throws\n\n// after\nFunction<Object[], R> f = Functions.array4Func(fn4);\nR r = f.apply(new Object[]{ a, b, c, d }); // length 4 matches arity","handlingStrategy":"validation","validationCode":"assert args.length == 4 : \"4-arity adapter requires length-4 array\";","typeGuard":null,"tryCatchPattern":"try {\n    R r = array4Fn.apply(args);\n} catch (IllegalArgumentException e) {\n    // fix array length to 4\n}","preventionTips":["Prefer public 4-source zip/combineLatest APIs.","Bind array length to source count; avoid hardcoded literals.","Add a length-4 input test."],"tags":["validation","argument","functions","arity","zip","rxjava"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}