{"record":{"id":"2ffe87b0c865edac","repo":"jwtk/jjwt","slug":"collection-must-not-be-null","errorCode":null,"errorMessage":"Collection must not be null","messagePattern":"Collection must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/io/jsonwebtoken/lang/Collections.java","lineNumber":287,"sourceCode":"    @SafeVarargs\n    public static <T> Set<T> concat(Set<T> c, T... elements) {\n        int size = Math.max(1, Collections.size(c) + io.jsonwebtoken.lang.Arrays.length(elements));\n        Set<T> set = new LinkedHashSet<>(size);\n        set.addAll(c);\n        java.util.Collections.addAll(set, elements);\n        return immutable(set);\n    }\n\n    /**\n     * Merge the given array into the given Collection.\n     *\n     * @param array      the array to merge (may be <code>null</code>)\n     * @param collection the target Collection to merge the array into\n     */\n    @SuppressWarnings(\"unchecked\")\n    public static void mergeArrayIntoCollection(Object array, Collection collection) {\n        if (collection == null) {\n            throw new IllegalArgumentException(\"Collection must not be null\");\n        }\n        Object[] arr = Objects.toObjectArray(array);\n        java.util.Collections.addAll(collection, arr);\n    }\n\n    /**\n     * Merge the given Properties instance into the given Map,\n     * copying all properties (key-value pairs) over.\n     * <p>Uses <code>Properties.propertyNames()</code> to even catch\n     * default properties linked into the original Properties instance.\n     *\n     * @param props the Properties instance to merge (may be <code>null</code>)\n     * @param map   the target Map to merge the properties into\n     */\n    @SuppressWarnings(\"unchecked\")\n    public static void mergePropertiesIntoMap(Properties props, Map map) {\n        if (map == null) {\n            throw new IllegalArgumentException(\"Map must not be null\");","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/api/src/main/java/io/jsonwebtoken/lang/Collections.java#L269-L305","documentation":"IllegalArgumentException thrown by io.jsonwebtoken.lang.Collections.mergeArrayIntoCollection when the target Collection argument is null. The source array may be null (it is tolerated), but the destination collection must exist.","triggerScenarios":"Calling Collections.mergeArrayIntoCollection(array, collection) with a null collection — e.g. a field never initialized or a getter that returned null.","commonSituations":"Passing an uninitialized List field; a helper method that returns null when no collection is configured; copy-paste where the array and collection arguments were swapped.","solutions":["Pass a non-null, mutable Collection (e.g. new ArrayList<>()) as the target","Check the argument order — a null first argument (the array) is allowed, a null second is not","Initialize the collection field before merging"],"exampleFix":"// before\nCollections.mergeArrayIntoCollection(values, targetList); // targetList is null\n// after\nList<Object> targetList = new ArrayList<>();\nCollections.mergeArrayIntoCollection(values, targetList);","handlingStrategy":"validation","validationCode":"if (collection == null) {\n    collection = new ArrayList<>();\n}\nCollections.mergeArrayIntoCollection(array, collection);","typeGuard":null,"tryCatchPattern":"try {\n    Collections.mergeArrayIntoCollection(array, collection);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Target collection must be initialized before merge\", e);\n}","preventionTips":["Always allocate target collections before merging into them","Note the asymmetry: null array is allowed, null collection is not","Check argument order when wrapping this API"],"tags":["null-argument","collections","precondition"],"backgroundTag":"null-argument","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"}