apache/maven · error · IllegalArgumentException
substring function requires 2 or 3 arguments
Error message
substring function requires 2 or 3 arguments
What it means
substring() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.substring accepts exactly two or three arguments (string, start, optional end) and throws IllegalArgumentException for any other count; the activator records '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:105
*/
public Object lower(List<Object> args) {
if (args.size() != 1) {
throw new IllegalArgumentException("lower function requires exactly one argument");
}
String s = ConditionParser.toString(args.get(0));
return s.toLowerCase();
}
/**
* Returns a substring of the given string.
*
* @param args A list containing 2 or 3 arguments: the string, start index, and optionally end index
* @return The substring
* @throws IllegalArgumentException if the number of arguments is not 2 or 3
*/
public Object substring(List<Object> args) {
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");
}View on GitHub (pinned to e4093d4e12)
Solutions
- Supply two or three arguments, e.g. substring(${java.version}, 0, 2) == '17'
- Remember the end index is optional and defaults to the string length, but the start index is mandatory
- Verify with mvn help:active-profiles after the fix
Example fix
<!-- before -->
<condition>substring(${java.version}) == '17'</condition>
<!-- after -->
<condition>substring(${java.version}, 0, 2) == '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, "substring", 2, 3); Try / catch
try {
Object r = new ConditionParser(functions, resolver).parse(condition);
} catch (IllegalArgumentException e) {
// wrong arity (also possible: StringIndexOutOfBounds values arrive as parse errors)
} Prevention
- substring needs (string, start) or (string, start, end) — never just the string
- Bounds are Java String.substring semantics: 0 <= start <= end <= length
When it happens
Trigger: A condition like substring(${java.version}) (one argument) or substring(${java.version}, 0, 2, 1) (four) — valid forms are substring(s, start) and substring(s, start, end).
Common situations: Expecting the string alone to be enough; carrying over an extra step/flags argument from another language's substring; forgetting the start index while extracting a prefix.
Related errors
- length function requires exactly one argument
- upper function requires exactly one argument
- lower function requires exactly one argument
- 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/9f6934040fcdc18e.
Report an issue: GitHub.