{"record":{"id":"b3c3610972c782e5","repo":"quarkusio/quarkus","slug":"failed-to-parse-maven-opts-mvnopts","errorCode":null,"errorMessage":"Failed to parse MAVEN_OPTS=${mvnOpts}","messagePattern":"Failed to parse MAVEN_OPTS=(.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/options/BootstrapMavenOptions.java","lineNumber":147,"sourceCode":"        }\n\n        final String mvnLine = System.getenv(MAVEN_CMD_LINE_ARGS);\n        if (mvnLine == null) {\n            // if the maven command line isn't available we are not checking for MAVEN_OPTS\n            return null;\n        }\n\n        String mvnOpts = System.getenv(\"MAVEN_OPTS\");\n        if (mvnOpts == null) {\n            return mvnLine;\n        }\n        // only retain system properties from MAVEN_OPTS, not something like --add-opens\n        try {\n            mvnOpts = Arrays.stream(CommandLineUtils.translateCommandline(mvnOpts))\n                    .filter(part -> part.startsWith(\"-\" + SYSTEM_PROPERTY))\n                    .collect(Collectors.joining(\" \"));\n        } catch (CommandLineException e) {\n            throw new IllegalStateException(\"Failed to parse MAVEN_OPTS=\" + mvnOpts, e);\n        }\n        if (mvnOpts.isEmpty()) {\n            return mvnLine;\n        }\n\n        final StringBuilder buf = new StringBuilder(mvnLine.length() + mvnOpts.length() + 1);\n        buf.append(mvnOpts);\n        if (!Character.isWhitespace(mvnLine.charAt(0))) {\n            buf.append(' ');\n        }\n        return buf.append(mvnLine).toString();\n    }\n\n    private final Map<String, Object> options;\n    private List<String> activeProfileIds;\n    private List<String> inactiveProfileIds;\n\n    private BootstrapMavenOptions(Map<String, Object> options) {","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/options/BootstrapMavenOptions.java#L129-L165","documentation":"getMavenCmdLine() reads the MAVEN_OPTS environment variable and keeps only system-property parts (-D...). Tokenizing MAVEN_OPTS with CommandLineUtils.translateCommandline can fail (unbalanced quotes etc.), producing IllegalStateException 'Failed to parse MAVEN_OPTS=<value>'.","triggerScenarios":"Calling BootstrapMavenOptions.newInstance() (which calls getMavenCmdLine) when the MAVEN_OPTS environment variable contains quoting that translateCommandline cannot parse - e.g. MAVEN_OPTS=\"-Xmx1g -Dfoo='bar (unterminated quote)\".","commonSituations":"Hand-edited MAVEN_OPTS in shell profiles with nested quotes, IDE or CI export of MAVEN_OPTS with escaped characters the plexus tokenizer rejects, values copied from docs with smart quotes, or JVM flags like --add-opens=\"x=y\" whose quotes got mangled.","solutions":["Print/echo $MAVEN_OPTS and fix the quoting (balanced, properly escaped quotes) or remove problematic entries","Move non -D flags (e.g. --add-opens) with tricky quoting into .mvn/jvm.config instead of MAVEN_OPTS","Run with MAVEN_OPTS unset to confirm this variable is the trigger, then re-add entries one at a time","Only keep simple -Dkey=value system properties in MAVEN_OPTS; this code filters for exactly that anyway"],"exampleFix":"// before\nexport MAVEN_OPTS=\"-Xmx2g -Dfoo=\\\"bar\\\"\"  # double-escaped\n// after\nexport MAVEN_OPTS=\"-Xmx2g -Dfoo=bar\"","handlingStrategy":"validation","validationCode":"String mvnOpts = System.getenv(\"MAVEN_OPTS\");\nif (mvnOpts != null) {\n    try {\n        CommandLineUtils.translateCommandline(mvnOpts);\n    } catch (CommandLineException e) {\n        throw new IllegalStateException(\"MAVEN_OPTS cannot be tokenized: \" + mvnOpts, e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    BootstrapMavenOptions options = BootstrapMavenOptions.newInstance(cmdLine);\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Failed to parse MAVEN_OPTS=\")) {\n        throw new IllegalStateException(\"Fix MAVEN_OPTS quoting: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Keep only simple -Dkey=value entries in MAVEN_OPTS","Put complex JVM flags like --add-opens in .mvn/jvm.config instead","Test shell profile changes with `echo $MAVEN_OPTS` in a fresh shell","Unset MAVEN_OPTS first when debugging parser failures to isolate the variable"],"tags":["environment","maven","command-line","maven-opts"],"backgroundTag":"invalid-maven-opts","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}