{"record":{"id":"02aee6b316f5d11e","repo":"ReactiveX/RxJava","slug":"array-of-size-5-expected-but-got","errorCode":null,"errorMessage":"Array of size 5 expected but got {}","messagePattern":"Array of size 5 expected but got (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java","lineNumber":510,"sourceCode":"                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            }\n            return f.apply((T1)a[0], (T2)a[1], (T3)a[2], (T4)a[3], (T5)a[4]);\n        }\n    }\n\n    record Array6Func<T1, T2, T3, T4, T5, T6, R>(\n            Function6<T1, T2, T3, T4, T5, T6, R> f) implements Function<Object[], R> {\n\n        @SuppressWarnings(\"unchecked\")\n            @Override\n            public R apply(Object[] a) throws Throwable {\n                if (a.length != 6) {\n                    throw new IllegalArgumentException(\"Array of size 6 expected but got \" + a.length);\n                }\n                return f.apply((T1) a[0], (T2) a[1], (T3) a[2], (T4) a[3], (T5) a[4], (T6) a[5]);\n            }\n        }\n","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java#L492-L528","documentation":"Thrown by Array5Func.apply(Object[]) when the array length is not exactly 5. Array5Func is a class (not a record) adapting Function5 to Function<Object[],R>, backing 5-way zip/combineLatest. The array arity must equal 5.","triggerScenarios":"A 5-arity adapter receives an Object[] of length != 5. Typically an internal or custom-operator wiring error; not normally reachable from public API usage.","commonSituations":"Dynamic source lists feeding a fixed 5-arity adapter; refactoring a fan-in that added/removed a source but left the adapter arity unchanged; manual test scaffolding with the wrong array size.","solutions":["Supply exactly 5 array elements to the 5-arity adapter; fix the array-construction logic.","Use the public 5-source zip/combineLatest overloads that handle arity internally.","Write a test asserting length-5 input at the call site.","Bind array length to the actual source count rather than a literal."],"exampleFix":"// before\nFunction<Object[], R> f = new Functions.Array5Func<>(fn5);\nR r = f.apply(new Object[]{ a, b, c, d }); // length 4 -> throws\n\n// after\nFunction<Object[], R> f = new Functions.Array5Func<>(fn5);\nR r = f.apply(new Object[]{ a, b, c, d, e }); // length 5 matches arity","handlingStrategy":"validation","validationCode":"assert args.length == 5 : \"5-arity adapter requires length-5 array\";","typeGuard":null,"tryCatchPattern":"try {\n    R r = array5Fn.apply(args);\n} catch (IllegalArgumentException e) {\n    // array length != 5; realign\n}","preventionTips":["Use public 5-source zip/combineLatest overloads.","Keep array length tied to the source list size.","Regression-test the arity boundary."],"tags":["validation","argument","functions","arity","zip","rxjava"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}