{"record":{"id":"cbae61f70b107739","repo":"jwtk/jjwt","slug":"source-is-not-an-array","errorCode":null,"errorMessage":"Source is not an array: ","messagePattern":"Source is not an array: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/lang/Objects.java","lineNumber":263,"sourceCode":"    /**\n     * Convert the given array (which may be a primitive array) to an\n     * object array (if necessary of primitive wrapper objects).\n     * <p>A <code>null</code> source value will be converted to an\n     * empty Object array.\n     *\n     * @param source the (potentially primitive) array\n     * @return the corresponding object array (never <code>null</code>)\n     * @throws IllegalArgumentException if the parameter is not an array\n     */\n    public static Object[] toObjectArray(Object source) {\n        if (source instanceof Object[]) {\n            return (Object[]) source;\n        }\n        if (source == null) {\n            return new Object[0];\n        }\n        if (!source.getClass().isArray()) {\n            throw new IllegalArgumentException(\"Source is not an array: \" + source);\n        }\n        int length = Array.getLength(source);\n        if (length == 0) {\n            return new Object[0];\n        }\n        Class wrapperType = Array.get(source, 0).getClass();\n        Object[] newArray = (Object[]) Array.newInstance(wrapperType, length);\n        for (int i = 0; i < length; i++) {\n            newArray[i] = Array.get(source, i);\n        }\n        return newArray;\n    }\n\n\n    //---------------------------------------------------------------------\n    // Convenience methods for content-based equality/hash-code handling\n    //---------------------------------------------------------------------\n","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/lang/Objects.java#L245-L281","documentation":"Thrown by Objects.toObjectArray when the given source object is neither an Object[] nor null and is not a primitive/other array type, so it cannot be converted to an Object[]. It is a defensive guard in array-conversion helpers.","triggerScenarios":"Passing a non-array object (e.g. a List, String, or arbitrary bean) to Objects.toObjectArray; the method only accepts arrays or null.","commonSituations":"Refactoring code that changed a varargs/array parameter to a plain object; accidentally passing a collection instead of an array; reflection-based code mis-detecting the argument type.","solutions":["Pass an actual array (e.g. new Object[]{...}) instead of a List or other object","Convert collections first: list.toArray(new Object[0])","If the input may be either, branch on source.getClass().isArray() before calling","Catch IllegalArgumentException if input is untrusted and handle the non-array case"],"exampleFix":"// before\nObject[] arr = Objects.toObjectArray(myList); // IllegalArgumentException\n// after\nObject[] arr = myList.toArray(new Object[0]);","handlingStrategy":"type-guard","validationCode":"if (source != null && !source.getClass().isArray()) throw new IllegalArgumentException(\"Expected an array, got: \" + source.getClass());","typeGuard":"static boolean isObjectArray(Object o) {\n    return o == null || o instanceof Object[] || (o != null && o.getClass().isArray());\n}","tryCatchPattern":"try {\n    Object[] arr = Objects.toObjectArray(source);\n} catch (IllegalArgumentException e) {\n    Object[] arr = new Object[]{ source }; // treat as single-element\n}","preventionTips":["Pass varargs or explicit arrays, not collections, into array-expecting helpers","Convert List/Collection with toArray(new Object[0]) first","Prefer Objects.toObjectArray only for genuinely array-typed inputs"],"tags":["java","arrays","type-mismatch"],"backgroundTag":"incompatible-source-type","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}