{"record":{"id":"e06191f3bd26c2eb","repo":"apache/maven","slug":"matches-function-requires-exactly-two-arguments","errorCode":null,"errorMessage":"matches function requires exactly two arguments","messagePattern":"matches 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":154,"sourceCode":"    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));\n        String regex = ConditionParser.toString(args.get(1));\n        return s.matches(regex);\n    }\n\n    /**\n     * Negates a boolean value.\n     *\n     * @param args A list containing a single boolean argument\n     * @return The negation of the input boolean\n     * @throws IllegalArgumentException if the number of arguments is not exactly one\n     */\n    public Object not(List<Object> args) {\n        if (args.size() != 1) {\n            throw new IllegalArgumentException(\"not function requires exactly one argument\");\n        }\n        return !ConditionParser.toBoolean(args.get(0));","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java#L136-L172","documentation":"matches() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.matches throws IllegalArgumentException unless exactly two string arguments (input, regex) are given; the activator converts it into 'Error parsing profile activation condition' and the profile stays inactive.","triggerScenarios":"A condition like matches(${java.version}) with only the string — the regex pattern argument is mandatory, e.g. matches(${java.version}, '17\\..*').","commonSituations":"Forgetting the pattern after renaming from another function; assuming the regex can be reused from a variable defined elsewhere in the condition; writing an invalid regex (which then fails separately in String.matches).","solutions":["Always pass two arguments: matches(${java.version}, '17\\..*')","Test the regex separately (e.g. jshell) before putting it in the condition","For simple prefix/suffix checks, prefer contains() or substring(), which cannot fail on pattern syntax"],"exampleFix":"<!-- before -->\n<condition>matches(${java.version})</condition>\n\n<!-- after -->\n<condition>matches(${java.version}, '17\\..*')</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, \"matches\", 2, 2);","typeGuard":null,"tryCatchPattern":"try {\n    Object r = new ConditionParser(functions, resolver).parse(condition);\n} catch (IllegalArgumentException e) {\n    // arity problem; a bad regex pattern surfaces as PatternSyntaxException during evaluation\n}","preventionTips":["matches is (input, regex); test regexes in jshell first","Remember matches() anchors the whole string — prefix matching needs .* suffixes"],"tags":["maven","profile-activation","condition-functions","argument-mismatch","regex"],"backgroundTag":"invalid-function-arguments","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}