{"record":{"id":"3db8cc2f22b3317a","repo":"apache/maven","slug":"exists-function-requires-exactly-one-argument","errorCode":null,"errorMessage":"exists function requires exactly one argument","messagePattern":"exists function requires exactly one argument","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java","lineNumber":202,"sourceCode":"        if (args.size() != 3) {\n            throw new IllegalArgumentException(\"if function requires exactly three arguments\");\n        }\n        boolean condition = ConditionParser.toBoolean(args.get(0));\n        return condition ? args.get(1) : args.get(2);\n    }\n\n    /**\n     * Checks if a file or directory exists at the given path.\n     *\n     * @param args A list containing a single string argument representing the path\n     * @return {@code true} if the file or directory exists, {@code false} otherwise\n     * @throws IllegalArgumentException if the number of arguments is not exactly one\n     * @throws ModelBuilderException if a problem occurs while walking the file system\n     * @throws InterpolatorException if an error occurs during interpolation\n     */\n    public Object exists(List<Object> args) {\n        if (args.size() != 1) {\n            throw new IllegalArgumentException(\"exists function requires exactly one argument\");\n        }\n        String path = ConditionParser.toString(args.get(0));\n        return context.exists(path, true);\n    }\n\n    /**\n     * Checks if a file or directory is missing at the given path.\n     *\n     * @param args A list containing a single string argument representing the path\n     * @return {@code true} if the file or directory does not exist, {@code false} otherwise\n     * @throws IllegalArgumentException if the number of arguments is not exactly one\n     * @throws ModelBuilderException if a problem occurs while walking the file system\n     * @throws InterpolatorException if an error occurs during interpolation\n     */\n    public Object missing(List<Object> args) {\n        if (args.size() != 1) {\n            throw new IllegalArgumentException(\"missing function requires exactly one argument\");\n        }","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionFunctions.java#L184-L220","documentation":"exists() is a built-in function of Maven 4.1 profile activation conditions (<activation><condition>). ConditionFunctions.exists throws IllegalArgumentException unless exactly one string argument (a path, optionally containing glob wildcards) is supplied; the activator converts it into 'Error parsing profile activation condition' and leaves the profile inactive.","triggerScenarios":"A condition like exists('src/main/groovy', true) — there is no second flag argument; the valid form is exists('src/main/groovy') or a glob like exists('${project.basedir}/src/**/*.java').","commonSituations":"Adding a 'glob enabled' boolean by analogy with the Java API (globbing is on by default); passing directory and file as two arguments; migrating the old <file exists=.../> activation XML into the new condition syntax.","solutions":["Use exactly one argument: exists('src/main/groovy')","Wildcards need no flag: exists('${project.basedir}/src/**/*.java') works as-is","Remember a non-readable directory can raise a separate ProjectBuilderException during the walk — keep globs narrow"],"exampleFix":"<!-- before -->\n<condition>exists('src/main/groovy', true)</condition>\n\n<!-- after -->\n<condition>exists('src/main/groovy')</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, \"exists\", 1, 1);","typeGuard":null,"tryCatchPattern":"try {\n    Object r = new ConditionParser(functions, resolver).parse(condition);\n} catch (IllegalArgumentException e) {\n    // arity error; IO problems during glob walks surface as ProjectBuilderException instead\n}","preventionTips":["exists takes one path argument; globbing is always enabled, no flag needed","Keep globbed paths narrow to avoid slow walks and IO failures"],"tags":["maven","profile-activation","condition-functions","argument-mismatch","file-check"],"backgroundTag":"invalid-function-arguments","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}