{"record":{"id":"2ee90783b66bae58","repo":"apache/maven","slug":"if-function-requires-exactly-three-arguments","errorCode":null,"errorMessage":"if function requires exactly three arguments","messagePattern":"if function requires exactly three 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":185,"sourceCode":"     */\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));\n    }\n\n    /**\n     * Implements an if-then-else operation.\n     *\n     * @param args A list containing three arguments: condition, value if true, value if false\n     * @return The second argument if the condition is true, the third argument otherwise\n     * @throws IllegalArgumentException if the number of arguments is not exactly three\n     */\n    @SuppressWarnings(\"checkstyle:MethodName\")\n    public Object if_(List<Object> args) {\n        if (args.size() != 3) {\n            throw new IllegalArgumentException(\"if function requires exactly three arguments\");\n        }\n        boolean condition = ConditionParser.toBoolean(args.get(0));\n        return condition ? args.get(1) : args.get(2);\n    }\n\n    /**\n     * Checks if a file or directory exists at the given path.\n     *\n     * @param args A list containing a single string argument representing the path\n     * @return {@code true} if the file or directory exists, {@code false} otherwise\n     * @throws IllegalArgumentException if the number of arguments is not exactly one\n     * @throws ModelBuilderException if a problem occurs while walking the file system\n     * @throws InterpolatorException if an error occurs during interpolation\n     */\n    public Object exists(List<Object> args) {\n        if (args.size() != 1) {\n            throw new IllegalArgumentException(\"exists function requires exactly one argument\");\n        }","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java#L167-L203","documentation":"if() (implemented as the method if_ in ConditionFunctions) is the ternary built-in of Maven 4.1 profile activation conditions (<activation><condition>). It throws IllegalArgumentException unless exactly three arguments (condition, valueIfTrue, valueIfFalse) are given; the activator reports 'Error parsing profile activation condition' and the profile does not activate.","triggerScenarios":"A condition like if(contains(${os.name},'Linux'), 'unix') missing the else branch — the parser requires all three arguments, e.g. if(cond, a, b).","commonSituations":"Dropping the else value while sketching; adding a fourth 'default' argument; forgetting that the condition argument must itself be a boolean expression, not a raw string.","solutions":["Always provide three arguments: if(contains(${os.name},'Linux'), 'unix', 'other')","Make sure the first argument evaluates to a boolean (comparison or boolean function)","Verify with mvn help:active-profiles after the fix"],"exampleFix":"<!-- before -->\n<condition>if(contains(${os.name},'Linux'), 'unix') == 'unix'</condition>\n\n<!-- after -->\n<condition>if(contains(${os.name},'Linux'), 'unix', 'other') == 'unix'</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, \"if\", 3, 3);","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":["if requires all three parts: condition, then-value, else-value","The Java method is if_ but in conditions it is written if","The first argument must be a boolean expression, not a bare string"],"tags":["maven","profile-activation","condition-functions","argument-mismatch","conditional"],"backgroundTag":"invalid-function-arguments","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}