quarkusio/quarkus · error · IllegalArgumentException

Invalid command line: ${cmdLine}

Error message

Invalid command line: ${cmdLine}

What it means

BootstrapMavenOptions.parse(String cmdLine) first translates the raw command line string into arguments using CommandLineUtils.translateCommandline. If the string has unbalanced quotes or otherwise cannot be tokenized (CommandLineException), it throws IllegalArgumentException with the offending command line in the message.

Source

Thrown at independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/options/BootstrapMavenOptions.java:61

    public static final String OFFLINE = "o";
    public static final String SUPRESS_SNAPSHOT_UPDATES = "nsu";
    public static final String UPDATE_SNAPSHOTS = "U";
    public static final String CHECKSUM_FAILURE_POLICY = "C";
    public static final String CHECKSUM_WARNING_POLICY = "c";
    public static final String BATCH_MODE = "B";
    public static final String NO_TRANSFER_PROGRESS = "ntp";
    public static final String SYSTEM_PROPERTY = "D";

    public static Map<String, Object> parse(String cmdLine) {
        if (cmdLine == null) {
            return Collections.emptyMap();
        }

        final String[] args;
        try {
            args = CommandLineUtils.translateCommandline(cmdLine);
        } catch (CommandLineException e) {
            throw new IllegalArgumentException("Invalid command line: " + cmdLine, e);
        }

        if (args.length == 0) {
            return Collections.emptyMap();
        }

        final String mavenHome = PropertyUtils.getProperty("maven.home");
        if (mavenHome == null) {
            try {
                return invokeParser(Thread.currentThread().getContextClassLoader(), args);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("Failed to load parser", e);
            }
        }

        final Path mvnLib = Paths.get(mavenHome).resolve("lib");
        if (!Files.exists(mvnLib)) {
            throw new IllegalStateException("Maven lib dir does not exist: " + mvnLib);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Print the cmdLine from the message and fix unbalanced or mismatched quotes before passing it
  2. Build the argument list programmatically and join carefully, or avoid embedding quoted -D values (Maven accepts -Dkey=value without quotes when passed as a single arg)
  3. Pre-test the string with org.codehaus.plexus.util.cli.CommandLineUtils.translateCommandline in a unit test
  4. Sanitize environment-provided values (MAVEN_OPTS) by trimming or re-quoting them before concatenation

Example fix

// before
BootstrapMavenOptions.newInstance("-Dmaven.repo.local=\"${HOME}/.m2"); // unterminated quote
// after
BootstrapMavenOptions.newInstance("-Dmaven.repo.local=" + repoDir.getAbsolutePath());
Defensive patterns

Strategy: validation

Validate before calling

// Check quotes are balanced before handing the string to the parser
long dq = cmdLine.chars().filter(c -> c == '"').count();
long sq = cmdLine.chars().filter(c -> c == '\'').count();
if (dq % 2 != 0 || sq % 2 != 0) {
    throw new IllegalArgumentException("Unbalanced quotes in command line: " + cmdLine);
}

Try / catch

try {
    BootstrapMavenOptions options = BootstrapMavenOptions.newInstance(cmdLine);
} catch (IllegalArgumentException e) {
    log.error("Cannot tokenize command line, fix quoting: " + e.getMessage());
    throw e;
}

Prevention

When it happens

Trigger: Calling BootstrapMavenOptions.newInstance(cmdLine) or parse() with a command line string containing unterminated quotes, e.g. -Dkey="value (missing closing quote) or mismatched single/double quotes.

Common situations: Programmatically building MAVEN_OPTS/maven command strings by string concatenation and dropping a quote, copying command lines from shell snippets where quoting semantics differ, env vars (MAVEN_OPTS) with nested quotes set incorrectly.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/d3e7d3361ef90a5c. Report an issue: GitHub.