{"record":{"id":"37d311081e44ccbf","repo":"apache/maven","slug":"length-function-requires-exactly-one-argument","errorCode":null,"errorMessage":"length function requires exactly one argument","messagePattern":"length function requires exactly one argument","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java","lineNumber":60,"sourceCode":"     *\n     * @param context The profile activation context\n     * @param versionParser The version parser for comparing versions\n     */\n    public ConditionFunctions(ProfileActivationContext context, VersionParser versionParser) {\n        this.context = context;\n        this.versionParser = versionParser;\n    }\n\n    /**\n     * Returns the length of the given string.\n     *\n     * @param args A list containing a single string argument\n     * @return The length of the string\n     * @throws IllegalArgumentException if the number of arguments is not exactly one\n     */\n    public Object length(List<Object> args) {\n        if (args.size() != 1) {\n            throw new IllegalArgumentException(\"length function requires exactly one argument\");\n        }\n        String s = ConditionParser.toString(args.get(0));\n        return s.length();\n    }\n\n    /**\n     * Converts the given string to uppercase.\n     *\n     * @param args A list containing a single string argument\n     * @return The uppercase version of the input string\n     * @throws IllegalArgumentException if the number of arguments is not exactly one\n     */\n    public Object upper(List<Object> args) {\n        if (args.size() != 1) {\n            throw new IllegalArgumentException(\"upper function requires exactly one argument\");\n        }\n        String s = ConditionParser.toString(args.get(0));\n        return s.toUpperCase();","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java#L42-L78","documentation":"length() is a built-in function of Maven 4.1 profile activation conditions (the <activation><condition> element). ConditionFunctions.length validates its argument list and throws IllegalArgumentException unless exactly one argument is given; ConditionProfileActivator catches it and records 'Error parsing profile activation condition: ...', leaving the profile inactive.","triggerScenarios":"Writing a condition like length() or length(${name}, 'x') — the function must be called as length(arg) with a single string, e.g. length(${project.artifactId}) == 5.","commonSituations":"Typing an extra comma or forgetting the argument in a hand-edited condition; copy-pasting expressions from docs of a different function set; upgrading to Maven 4.1 and using the new condition syntax for the first time.","solutions":["Rewrite the call as length(x) with exactly one argument, e.g. length(${project.artifactId}) == 5","Re-run mvn help:active-profiles (or the build) to confirm the profile now activates","Check the Maven 4.1 condition-function reference for the exact signature before adding more calls"],"exampleFix":"<!-- before -->\n<condition>length(${project.artifactId}, 0) == 5</condition>\n\n<!-- after -->\n<condition>length(${project.artifactId}) == 5</condition>","handlingStrategy":"validation","validationCode":"// Lint a condition expression for the arity of a given function (no nested calls in args)\nstatic 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, \"length\", 1, 1);","typeGuard":null,"tryCatchPattern":"try {\n    Object r = new ConditionParser(functions, resolver).parse(condition);\n} catch (IllegalArgumentException e) {\n    // wrong arity or bad operand; report the condition string and keep the profile inactive\n}","preventionTips":["Keep a table of the built-in condition functions and their arities next to your parent pom","Smoke-test new activations with mvn help:active-profiles before committing","Note that methods declared with a trailing underscore (if_) are used in conditions without it (if)"],"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"}