apache/maven · error · IllegalArgumentException
if function requires exactly three arguments
Error message
if function requires exactly three arguments
What it means
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.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java:185
*/
public Object not(List<Object> args) {
if (args.size() != 1) {
throw new IllegalArgumentException("not function requires exactly one argument");
}
return !ConditionParser.toBoolean(args.get(0));
}
/**
* Implements an if-then-else operation.
*
* @param args A list containing three arguments: condition, value if true, value if false
* @return The second argument if the condition is true, the third argument otherwise
* @throws IllegalArgumentException if the number of arguments is not exactly three
*/
@SuppressWarnings("checkstyle:MethodName")
public Object if_(List<Object> args) {
if (args.size() != 3) {
throw new IllegalArgumentException("if function requires exactly three arguments");
}
boolean condition = ConditionParser.toBoolean(args.get(0));
return condition ? args.get(1) : args.get(2);
}
/**
* Checks if a file or directory exists at the given path.
*
* @param args A list containing a single string argument representing the path
* @return {@code true} if the file or directory exists, {@code false} otherwise
* @throws IllegalArgumentException if the number of arguments is not exactly one
* @throws ModelBuilderException if a problem occurs while walking the file system
* @throws InterpolatorException if an error occurs during interpolation
*/
public Object exists(List<Object> args) {
if (args.size() != 1) {
throw new IllegalArgumentException("exists function requires exactly one argument");
}View on GitHub (pinned to e4093d4e12)
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
Example fix
<!-- before -->
<condition>if(contains(${os.name},'Linux'), 'unix') == 'unix'</condition>
<!-- after -->
<condition>if(contains(${os.name},'Linux'), 'unix', 'other') == 'unix'</condition> Defensive patterns
Strategy: validation
Validate before calling
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, "if", 3, 3); Try / catch
try {
Object r = new ConditionParser(functions, resolver).parse(condition);
} catch (IllegalArgumentException e) {
// report and treat the profile as inactive
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- length function requires exactly one argument
- 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
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/2ee90783b66bae58.
Report an issue: GitHub.