apache/maven · error · IllegalArgumentException
matches function requires exactly two arguments
Error message
matches function requires exactly two arguments
What it means
matches() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.matches throws IllegalArgumentException unless exactly two string arguments (input, regex) are given; the activator converts it into 'Error parsing profile activation condition' and the profile stays inactive.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java:154
public Object contains(List<Object> args) {
if (args.size() != 2) {
throw new IllegalArgumentException("contains function requires exactly two arguments");
}
String s = ConditionParser.toString(args.get(0));
String substring = ConditionParser.toString(args.get(1));
return s.contains(substring);
}
/**
* Checks if a string matches a given regular expression.
*
* @param args A list containing two strings: the string to check and the regex pattern
* @return true if the string matches the regex, false otherwise
* @throws IllegalArgumentException if the number of arguments is not exactly two
*/
public Object matches(List<Object> args) {
if (args.size() != 2) {
throw new IllegalArgumentException("matches function requires exactly two arguments");
}
String s = ConditionParser.toString(args.get(0));
String regex = ConditionParser.toString(args.get(1));
return s.matches(regex);
}
/**
* Negates a boolean value.
*
* @param args A list containing a single boolean argument
* @return The negation of the input boolean
* @throws IllegalArgumentException if the number of arguments is not exactly one
*/
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));View on GitHub (pinned to e4093d4e12)
Solutions
- Always pass two arguments: matches(${java.version}, '17\..*')
- Test the regex separately (e.g. jshell) before putting it in the condition
- For simple prefix/suffix checks, prefer contains() or substring(), which cannot fail on pattern syntax
Example fix
<!-- before -->
<condition>matches(${java.version})</condition>
<!-- after -->
<condition>matches(${java.version}, '17\..*')</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, "matches", 2, 2); Try / catch
try {
Object r = new ConditionParser(functions, resolver).parse(condition);
} catch (IllegalArgumentException e) {
// arity problem; a bad regex pattern surfaces as PatternSyntaxException during evaluation
} Prevention
- matches is (input, regex); test regexes in jshell first
- Remember matches() anchors the whole string — prefix matching needs .* suffixes
When it happens
Trigger: A condition like matches(${java.version}) with only the string — the regex pattern argument is mandatory, e.g. matches(${java.version}, '17\..*').
Common situations: Forgetting the pattern after renaming from another function; assuming the regex can be reused from a variable defined elsewhere in the condition; writing an invalid regex (which then fails separately in String.matches).
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/e06191f3bd26c2eb.
Report an issue: GitHub.