{"record":{"id":"90e64a1bb7bea429","repo":"apache/maven","slug":"failed-to-parse-arguments-from-file-atfile","errorCode":null,"errorMessage":"Failed to parse arguments from file (${atFile}): ${message}","messagePattern":"Failed to parse arguments from file \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenParser.java","lineNumber":72,"sourceCode":"        }\n        return LayeredMavenOptions.layerMavenOptions(result);\n    }\n\n    protected MavenOptions parseMavenCliOptions(List<String> args) {\n        try {\n            return parseArgs(Options.SOURCE_CLI, args);\n        } catch (ParseException e) {\n            throw new IllegalArgumentException(\"Failed to parse CLI arguments: \" + e.getMessage(), e.getCause());\n        }\n    }\n\n    protected MavenOptions parseMavenAtFileOptions(Path atFile) {\n        try (Stream<String> lines = Files.lines(atFile, StandardCharsets.UTF_8)) {\n            List<String> args =\n                    lines.filter(arg -> !arg.isEmpty() && !arg.startsWith(\"#\")).toList();\n            return parseArgs(\"atFile\", args);\n        } catch (ParseException e) {\n            throw new IllegalArgumentException(\n                    \"Failed to parse arguments from file (\" + atFile + \"): \" + e.getMessage(), e.getCause());\n        } catch (IOException e) {\n            throw new IllegalStateException(\"Error reading config file: \" + atFile, e);\n        }\n    }\n\n    protected MavenOptions parseMavenConfigOptions(Path configFile) {\n        try (Stream<String> lines = Files.lines(configFile, StandardCharsets.UTF_8)) {\n            List<String> args =\n                    lines.filter(arg -> !arg.isEmpty() && !arg.startsWith(\"#\")).toList();\n            MavenOptions options = parseArgs(\"maven.config\", args);\n            if (options.goals().isPresent()) {\n                // This file can only contain options, not args (goals or phases)\n                throw new IllegalArgumentException(\"Unrecognized entries in maven.config (\" + configFile + \") file: \"\n                        + options.goals().get());\n            }\n            return options;\n        } catch (ParseException e) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenParser.java#L54-L90","documentation":"Maven supports @argfiles (`mvn @/path/to/file`); MavenParser.parseMavenAtFileOptions reads the file (empty and `#` lines dropped, each remaining line is one argument) and parses them with Commons CLI. This error means the arguments inside the file failed parsing - the same defect class as a bad command line, but hidden in the file. The atFile path and the ParseException reason are included in the message.","triggerScenarios":"An @argfile line carrying two tokens (e.g. `-T 1C` on one line, which is parsed as a single bogus argument since each line is exactly one argv entry), an unknown option, or an option missing its value inside the file.","commonSituations":"Argfiles shared across teams and Maven versions (an option removed in Maven 4 breaks the file); editors inserting a BOM or smart quotes; token/value pairs written on one line out of shell-script habit.","solutions":["Open the file named in the message and fix the token the ParseException text points at.","Put each argument on its own line - never an option and its value on the same line.","Remove options that do not exist in the Maven version running the build.","Resave the file as plain UTF-8 without BOM, LF line endings, no smart quotes.","Prefer .mvn/maven.config for stable options and keep the @argfile only for per-run values."],"exampleFix":"# before: build.args - one line = one argument, so '-T 1C' is one bad token\n-T 1C\nclean\npackage\n\n# after: option and value on separate lines\n-T\n1C\nclean\npackage","handlingStrategy":"validation","validationCode":"List<String> lines = Files.readAllLines(atFile, StandardCharsets.UTF_8).stream()\n        .filter(l -> !l.isEmpty() && !l.startsWith(\"#\")).toList();\nfor (String line : lines) {\n    if (line.chars().anyMatch(Character::isWhitespace)) {\n        throw new IllegalArgumentException(\"Argfile line carries more than one token: \" + line);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    new MavenParser().parseMavenAtFileOptions(atFile);\n} catch (IllegalArgumentException e) { /* parse error in file */ report(e); } catch (IllegalStateException e) { /* unreadable file */ report(e); }","preventionTips":["One argument per line in every @argfile; lint the file in a pre-commit hook.","Run `mvn @file -v` as a cheap parse check in CI before real builds."],"tags":["maven","cli","argfile","argument-parsing"],"backgroundTag":"cli-argument-parsing-failed","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}