{"record":{"id":"7f29cbc8b7ca997b","repo":"ReactiveX/RxJava","slug":"array-of-size-3-expected-but-got","errorCode":null,"errorMessage":"Array of size 3 expected but got {}","messagePattern":"Array of size 3 expected but got (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java","lineNumber":481,"sourceCode":"    record Array2Func<T1, T2, R>(BiFunction<? super T1, ? super T2, ? extends R> f) implements Function<Object[], R> {\n\n        @SuppressWarnings(\"unchecked\")\n            @Override\n            public R apply(Object[] a) throws Throwable {\n                if (a.length != 2) {\n                    throw new IllegalArgumentException(\"Array of size 2 expected but got \" + a.length);\n                }\n                return f.apply((T1) a[0], (T2) a[1]);\n            }\n        }\n\n    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> {","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/internal/functions/Functions.java#L463-L499","documentation":"Thrown by Array3Func.apply(Object[]) when the array length is not exactly 3. Array3Func adapts a Function3 (3-ary) to Function<Object[],R>, used internally by 3-way zip/combineLatest fan-in. The arity of the array must equal the number of sources the function expects.","triggerScenarios":"A 3-arity array function adapter receives an Object[] whose length != 3. Reachable mainly from custom/test operator code that mismatches the number of combined sources against the adapter arity.","commonSituations":"Building a 3-way combine/zip manually with an array assembled from a variable number of sources; copy-pasting a 2-source adapter pattern into a 3-source scenario without updating the array construction; reflective source assembly.","solutions":["Make the Object[] length exactly 3 when invoking a 3-arity adapter; fix the code that assembles the array.","Use the public 3-source zip/combineLatest overloads, which manage arity correctly, instead of manual adapters.","Add a test asserting the array passed to a Function3 adapter has length 3.","Derive array length from the live source count, never from a separate hardcoded literal."],"exampleFix":"// before\nFunction<Object[], R> f = Functions.array3Func(fn3);\nR r = f.apply(new Object[]{ a, b }); // length 2 -> throws\n\n// after\nFunction<Object[], R> f = Functions.array3Func(fn3);\nR r = f.apply(new Object[]{ a, b, c }); // length 3 matches arity","handlingStrategy":"validation","validationCode":"assert args.length == 3 : \"3-arity adapter requires length-3 array\";\n// couple the array size to the number of combined sources","typeGuard":null,"tryCatchPattern":"try {\n    R r = array3Fn.apply(args);\n} catch (IllegalArgumentException e) {\n    // re-align source count with the 3-arity function\n}","preventionTips":["Use public 3-source zip/combineLatest overloads to avoid manual arity management.","When refactoring a fan-in, update both the adapter arity and the array together.","Test with arrays of length 2, 3, and 4 to lock the contract."],"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"}