apache/maven · error · IllegalArgumentException
indexOf function requires exactly two arguments
Error message
indexOf function requires exactly two arguments
What it means
indexOf() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.indexOf throws IllegalArgumentException unless exactly two string arguments (haystack, needle) are given; the activator turns it into '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:122
if (args.size() < 2 || args.size() > 3) {
throw new IllegalArgumentException("substring function requires 2 or 3 arguments");
}
String s = ConditionParser.toString(args.get(0));
int start = toInt(args.get(1));
int end = args.size() == 3 ? toInt(args.get(2)) : s.length();
return s.substring(start, end);
}
/**
* Finds the index of a substring within a string.
*
* @param args A list containing two strings: the main string and the substring to find
* @return The index of the substring, or -1 if not found
* @throws IllegalArgumentException if the number of arguments is not exactly two
*/
public Object indexOf(List<Object> args) {
if (args.size() != 2) {
throw new IllegalArgumentException("indexOf function requires exactly two arguments");
}
String s = ConditionParser.toString(args.get(0));
String substring = ConditionParser.toString(args.get(1));
return s.indexOf(substring);
}
/**
* Checks if a string contains a given substring.
*
* @param args A list containing two strings: the main string and the substring to check
* @return true if the main string contains the substring, false otherwise
* @throws IllegalArgumentException if the number of arguments is not exactly two
*/
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));View on GitHub (pinned to e4093d4e12)
Solutions
- Use exactly two arguments: indexOf(${os.name}, 'Win') >= 0
- If you only need a yes/no answer, prefer contains(${os.name}, 'Win')
- Verify with mvn help:active-profiles after the fix
Example fix
<!-- before -->
<condition>indexOf(${os.name}) >= 0</condition>
<!-- after -->
<condition>indexOf(${os.name}, 'Win') >= 0</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, "indexOf", 2, 2); Try / catch
try {
Object r = new ConditionParser(functions, resolver).parse(condition);
} catch (IllegalArgumentException e) {
// report and treat the profile as inactive
} Prevention
- indexOf has no fromIndex overload in conditions; use contains() for membership tests
When it happens
Trigger: A condition like indexOf(${os.name}) with only the string, or indexOf(${os.name}, 'Win', 0) with a fromIndex — the parser only supports the two-argument form returning the first index or -1.
Common situations: Habit from Java's String.indexOf(str, fromIndex); forgetting the needle; intending contains() but typing indexOf() and dropping an argument.
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
- contains function requires exactly two arguments
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/1fdcfb8050c4fd2b.
Report an issue: GitHub.