{"record":{"id":"1fdcfb8050c4fd2b","repo":"apache/maven","slug":"indexof-function-requires-exactly-two-arguments","errorCode":null,"errorMessage":"indexOf function requires exactly two arguments","messagePattern":"indexOf function requires exactly two arguments","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java","lineNumber":122,"sourceCode":"        if (args.size() < 2 || args.size() > 3) {\n            throw new IllegalArgumentException(\"substring function requires 2 or 3 arguments\");\n        }\n        String s = ConditionParser.toString(args.get(0));\n        int start = toInt(args.get(1));\n        int end = args.size() == 3 ? toInt(args.get(2)) : s.length();\n        return s.substring(start, end);\n    }\n\n    /**\n     * Finds the index of a substring within a string.\n     *\n     * @param args A list containing two strings: the main string and the substring to find\n     * @return The index of the substring, or -1 if not found\n     * @throws IllegalArgumentException if the number of arguments is not exactly two\n     */\n    public Object indexOf(List<Object> args) {\n        if (args.size() != 2) {\n            throw new IllegalArgumentException(\"indexOf function requires exactly two arguments\");\n        }\n        String s = ConditionParser.toString(args.get(0));\n        String substring = ConditionParser.toString(args.get(1));\n        return s.indexOf(substring);\n    }\n\n    /**\n     * Checks if a string contains a given substring.\n     *\n     * @param args A list containing two strings: the main string and the substring to check\n     * @return true if the main string contains the substring, false otherwise\n     * @throws IllegalArgumentException if the number of arguments is not exactly two\n     */\n    public Object contains(List<Object> args) {\n        if (args.size() != 2) {\n            throw new IllegalArgumentException(\"contains function requires exactly two arguments\");\n        }\n        String s = ConditionParser.toString(args.get(0));","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java#L104-L140","documentation":"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.","triggerScenarios":"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.","commonSituations":"Habit from Java's String.indexOf(str, fromIndex); forgetting the needle; intending contains() but typing indexOf() and dropping an argument.","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"],"exampleFix":"<!-- before -->\n<condition>indexOf(${os.name}) >= 0</condition>\n\n<!-- after -->\n<condition>indexOf(${os.name}, 'Win') >= 0</condition>","handlingStrategy":"validation","validationCode":"static boolean arityOk(String condition, String fn, int min, int max) {\n    int i = condition.indexOf(fn + \"(\");\n    if (i < 0) return true;\n    String args = condition.substring(i + fn.length() + 1, condition.indexOf(')', i));\n    int n = args.isBlank() ? 0 : args.split(\",\", -1).length;\n    return n >= min && n <= max;\n}\nboolean ok = arityOk(condition, \"indexOf\", 2, 2);","typeGuard":null,"tryCatchPattern":"try {\n    Object r = new ConditionParser(functions, resolver).parse(condition);\n} catch (IllegalArgumentException e) {\n    // report and treat the profile as inactive\n}","preventionTips":["indexOf has no fromIndex overload in conditions; use contains() for membership tests"],"tags":["maven","profile-activation","condition-functions","argument-mismatch","string"],"backgroundTag":"invalid-function-arguments","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}