{"record":{"id":"7bbf4304cf87d548","repo":"flowable/flowable-engine","slug":"the-input-should-always-be-even-since-we-expect-a","errorCode":null,"errorMessage":"The input should always be even since we expect a list of key-value pairs!","messagePattern":"The input should always be even since we expect a list of key-value pairs!","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/CollectionUtil.java","lineNumber":55,"sourceCode":"     * Helper method that creates a singleton map.\n     * \n     * Alternative for Collections.singletonMap(), since that method returns a generic typed map depending on the input type, but we often need a String, Object map.\n     */\n    public static Map<String, Object> singletonMap(String key, Object value) {\n        Map<String, Object> map = new HashMap<>(1);\n        map.put(key, value);\n        return map;\n    }\n\n    /**\n     * Helper method to easily create a map.\n     * \n     * Takes as input a varargs containing the key1, value1, key2, value2, etc. Note: although an Object, we will cast the key to String internally.\n     */\n    public static Map<String, Object> map(Object... objects) {\n\n        if (objects.length % 2 != 0) {\n            throw new FlowableIllegalArgumentException(\"The input should always be even since we expect a list of key-value pairs!\");\n        }\n\n        Map<String, Object> map = new HashMap<>();\n        for (int i = 0; i < objects.length; i += 2) {\n            map.put((String) objects[i], objects[i + 1]);\n        }\n\n        return map;\n    }\n\n    public static boolean isEmpty(@SuppressWarnings(\"rawtypes\") Collection collection) {\n        return (collection == null || collection.isEmpty());\n    }\n\n    public static boolean isNotEmpty(@SuppressWarnings(\"rawtypes\") Collection collection) {\n        return !isEmpty(collection);\n    }\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/util/CollectionUtil.java#L37-L73","documentation":"CollectionUtil.map(Object...) builds a Map from alternating key/value varargs and throws FlowableIllegalArgumentException when the number of arguments is odd. Keys are cast to String, so an even count of pairs is required.","triggerScenarios":"Calling CollectionUtil.map(\"k1\", v1, \"k2\") — a vararg list with an odd element count, usually from a manually edited or generated argument list.","commonSituations":"Hand-writing process-variable maps and forgetting a value; refactoring removed an entry; dynamic argument array assembled with a missing element.","solutions":["Count the arguments and add the missing key or value to make pairs complete","Prefer building the map directly (new HashMap<>) or Map.of(...) instead of varargs","Write a helper that asserts pairs at the call site before invoking map"],"exampleFix":"// before\nCollectionUtil.map(\"orderId\", orderId, \"customerId\");\n// after\nCollectionUtil.map(\"orderId\", orderId, \"customerId\", customerId);","handlingStrategy":"validation","validationCode":"if (args.length % 2 != 0) {\n    throw new IllegalArgumentException(\"map() requires an even number of key/value arguments\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Map<String, Object> vars = CollectionUtil.map(args);\n} catch (FlowableIllegalArgumentException e) {\n    logger.error(\"Malformed key/value varargs: {}\", e.getMessage());\n}","preventionTips":["Prefer Map.of(...) or explicit put() calls over key/value varargs","Keep key-value pairs on one line each when writing varargs literals","Add a unit test per map() call site in critical paths"],"tags":["flowable","varargs","map","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}