{"record":{"id":"e5e36b717a8b6555","repo":"apache/maven","slug":"contains-function-requires-exactly-two-arguments","errorCode":null,"errorMessage":"contains function requires exactly two arguments","messagePattern":"contains function requires exactly two arguments","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java","lineNumber":138,"sourceCode":"    public Object indexOf(List<Object> args) {\n        if (args.size() != 2) {\n            throw new IllegalArgumentException(\"indexOf function requires exactly two arguments\");\n        }\n        String s = ConditionParser.toString(args.get(0));\n        String substring = ConditionParser.toString(args.get(1));\n        return s.indexOf(substring);\n    }\n\n    /**\n     * Checks if a string contains a given substring.\n     *\n     * @param args A list containing two strings: the main string and the substring to check\n     * @return true if the main string contains the substring, false otherwise\n     * @throws IllegalArgumentException if the number of arguments is not exactly two\n     */\n    public Object contains(List<Object> args) {\n        if (args.size() != 2) {\n            throw new IllegalArgumentException(\"contains function requires exactly two arguments\");\n        }\n        String s = ConditionParser.toString(args.get(0));\n        String substring = ConditionParser.toString(args.get(1));\n        return s.contains(substring);\n    }\n\n    /**\n     * Checks if a string matches a given regular expression.\n     *\n     * @param args A list containing two strings: the string to check and the regex pattern\n     * @return true if the string matches the regex, false otherwise\n     * @throws IllegalArgumentException if the number of arguments is not exactly two\n     */\n    public Object matches(List<Object> args) {\n        if (args.size() != 2) {\n            throw new IllegalArgumentException(\"matches function requires exactly two arguments\");\n        }\n        String s = ConditionParser.toString(args.get(0));","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java#L120-L156","documentation":"contains() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.contains throws IllegalArgumentException unless exactly two string arguments (string, substring) are supplied; the activator reports 'Error parsing profile activation condition' and leaves the profile inactive.","triggerScenarios":"A condition like contains(${os.name}) with only one argument or contains('Linux', ${os.name}, true) with three — the only valid form is contains(haystack, needle).","commonSituations":"Forgetting the needle while sketching a condition; adding a case-sensitivity flag that does not exist (combine with lower()/upper() instead); argument order swapped, which yields wrong results rather than an error.","solutions":["Use exactly two arguments in the order (string, substring): contains(${os.name}, 'Linux')","For case-insensitive matching wrap both sides: contains(lower(${os.name}), 'linux')","Verify with mvn help:active-profiles after the fix"],"exampleFix":"<!-- before -->\n<condition>contains(${os.name})</condition>\n\n<!-- after -->\n<condition>contains(${os.name}, 'Linux')</condition>","handlingStrategy":"validation","validationCode":"static boolean arityOk(String condition, String fn, int min, int max) {\n    int i = condition.indexOf(fn + \"(\");\n    if (i < 0) return true;\n    String args = condition.substring(i + fn.length() + 1, condition.indexOf(')', i));\n    int n = args.isBlank() ? 0 : args.split(\",\", -1).length;\n    return n >= min && n <= max;\n}\nboolean ok = arityOk(condition, \"contains\", 2, 2);","typeGuard":null,"tryCatchPattern":"try {\n    Object r = new ConditionParser(functions, resolver).parse(condition);\n} catch (IllegalArgumentException e) {\n    // report and treat the profile as inactive\n}","preventionTips":["contains is (haystack, needle) only; no ignore-case flag — wrap arguments in lower()/upper()"],"tags":["maven","profile-activation","condition-functions","argument-mismatch","string"],"backgroundTag":"invalid-function-arguments","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}