apache/maven · error · IllegalArgumentException
exists function requires exactly one argument
Error message
exists function requires exactly one argument
What it means
exists() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.exists throws IllegalArgumentException unless exactly one string argument (a path, optionally containing glob wildcards) is supplied; the activator converts it into 'Error parsing profile activation condition' and leaves the profile inactive.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java:202
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");
}
String path = ConditionParser.toString(args.get(0));
return context.exists(path, true);
}
/**
* Checks if a file or directory is missing at the given path.
*
* @param args A list containing a single string argument representing the path
* @return {@code true} if the file or directory does not exist, {@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 missing(List<Object> args) {
if (args.size() != 1) {
throw new IllegalArgumentException("missing function requires exactly one argument");
}View on GitHub (pinned to e4093d4e12)
Solutions
- Use exactly one argument: exists('src/main/groovy')
- Wildcards need no flag: exists('${project.basedir}/src/**/*.java') works as-is
- Remember a non-readable directory can raise a separate ProjectBuilderException during the walk — keep globs narrow
Example fix
<!-- before -->
<condition>exists('src/main/groovy', true)</condition>
<!-- after -->
<condition>exists('src/main/groovy')</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, "exists", 1, 1); Try / catch
try {
Object r = new ConditionParser(functions, resolver).parse(condition);
} catch (IllegalArgumentException e) {
// arity error; IO problems during glob walks surface as ProjectBuilderException instead
} Prevention
- exists takes one path argument; globbing is always enabled, no flag needed
- Keep globbed paths narrow to avoid slow walks and IO failures
When it happens
Trigger: A condition like exists('src/main/groovy', true) — there is no second flag argument; the valid form is exists('src/main/groovy') or a glob like exists('${project.basedir}/src/**/*.java').
Common situations: Adding a 'glob enabled' boolean by analogy with the Java API (globbing is on by default); passing directory and file as two arguments; migrating the old <file exists=.../> activation XML into the new condition syntax.
Related errors
- missing function requires exactly one argument
- 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
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/3db8cc2f22b3317a.
Report an issue: GitHub.