apache/maven · error · IllegalArgumentException

inrange function requires exactly two arguments

Error message

inrange function requires exactly two arguments

What it means

inrange() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.inrange throws IllegalArgumentException unless exactly two string arguments are given in the order (version, range); the range is parsed with the Maven VersionParser, e.g. inrange(${maven.version}, '[4.0,)'). The activator converts the failure into 'Error parsing profile activation condition'.

Source

Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java:234

     */
    public Object missing(List<Object> args) {
        if (args.size() != 1) {
            throw new IllegalArgumentException("missing function requires exactly one argument");
        }
        String path = ConditionParser.toString(args.get(0));
        return !context.exists(path, true);
    }

    /**
     * Checks if a version is within a specified version range.
     *
     * @param args A list containing two strings: the version to check and the version range
     * @return true if the version is within the range, false otherwise
     * @throws IllegalArgumentException if the number of arguments is not exactly two
     */
    public Object inrange(List<Object> args) {
        if (args.size() != 2) {
            throw new IllegalArgumentException("inrange function requires exactly two arguments");
        }
        String version = ConditionParser.toString(args.get(0));
        String range = ConditionParser.toString(args.get(1));
        return versionParser.parseVersionRange(range).contains(versionParser.parseVersion(version));
    }

    /**
     * Checks whether a given executable can be found in the system PATH, or – if an
     * absolute / relative path is supplied – whether that path itself is an executable file.
     *
     * <p><strong>Warning:</strong> relying on local system environment variables like PATH makes
     * profile activation non-reproducible. This function should typically be used only in local
     * build profiles and not in consumer POMs that are published to a remote repository.</p>
     *
     * <p>Usage examples in a profile {@code <condition>}:
     * <pre>
     *   executable('musl-gcc')
     *   executable('x86_64-linux-musl-gcc')

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Always pass (version, range) as two arguments: inrange(${maven.version}, '[4.0,)')
  2. Use ${maven.version} (not java.version) when you mean the Maven runtime version; use jdk-related properties for JDK checks
  3. Verify with mvn help:active-profiles after the fix

Example fix

<!-- before -->
<condition>inrange(${maven.version})</condition>

<!-- after -->
<condition>inrange(${maven.version}, '[4.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, "inrange", 2, 2);

Try / catch

try {
    Object r = new ConditionParser(functions, resolver).parse(condition);
} catch (IllegalArgumentException e) {
    // arity error; malformed ranges throw from VersionParser instead
}

Prevention

When it happens

Trigger: A condition like inrange(${maven.version}) missing the range, or a third argument — only the two-argument form (version, range) is accepted.

Common situations: Migrating from the old jdk-activation style checks to the new condition syntax; forgetting which argument comes first (order matters: version first, range second); typos in the range syntax, which instead surface as a VersionParser error.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/6e13ae3dff649bd3. Report an issue: GitHub.