apache/maven · error · IllegalArgumentException
length function requires exactly one argument
Error message
length function requires exactly one argument
What it means
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.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java:60
*
* @param context The profile activation context
* @param versionParser The version parser for comparing versions
*/
public ConditionFunctions(ProfileActivationContext context, VersionParser versionParser) {
this.context = context;
this.versionParser = versionParser;
}
/**
* Returns the length of the given string.
*
* @param args A list containing a single string argument
* @return The length of the string
* @throws IllegalArgumentException if the number of arguments is not exactly one
*/
public Object length(List<Object> args) {
if (args.size() != 1) {
throw new IllegalArgumentException("length function requires exactly one argument");
}
String s = ConditionParser.toString(args.get(0));
return s.length();
}
/**
* Converts the given string to uppercase.
*
* @param args A list containing a single string argument
* @return The uppercase version of the input string
* @throws IllegalArgumentException if the number of arguments is not exactly one
*/
public Object upper(List<Object> args) {
if (args.size() != 1) {
throw new IllegalArgumentException("upper function requires exactly one argument");
}
String s = ConditionParser.toString(args.get(0));
return s.toUpperCase();View on GitHub (pinned to e4093d4e12)
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
Example fix
<!-- before -->
<condition>length(${project.artifactId}, 0) == 5</condition>
<!-- after -->
<condition>length(${project.artifactId}) == 5</condition> Defensive patterns
Strategy: validation
Validate before calling
// Lint a condition expression for the arity of a given function (no nested calls in args)
static boolean arityOk(String condition, String fn, int min, int max) {
int i = condition.indexOf(fn + "(");
if (i < 0) return true;
String args = condition.substring(i + fn.length() + 1, condition.indexOf(')', i));
int n = args.isBlank() ? 0 : args.split(",", -1).length;
return n >= min && n <= max;
}
boolean ok = arityOk(condition, "length", 1, 1); Try / catch
try {
Object r = new ConditionParser(functions, resolver).parse(condition);
} catch (IllegalArgumentException e) {
// wrong arity or bad operand; report the condition string and keep the profile inactive
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- upper function requires exactly one argument
- lower function requires exactly one argument
- substring function requires 2 or 3 arguments
- indexOf function requires exactly two arguments
- contains function requires exactly two arguments
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/37d311081e44ccbf.
Report an issue: GitHub.