{"record":{"id":"b50bd76da41a7200","repo":"SonarSource/sonarqube","slug":"command-line-argument-must-start-with-d-for-exam","errorCode":null,"errorMessage":"Command-line argument must start with -D, for example -Dsonar.jdbc.username=sonar. Got: %s","messagePattern":"Command-line argument must start with -D, for example -Dsonar\\.jdbc\\.username=sonar\\. Got: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/config/CommandLineParser.java","lineNumber":55,"sourceCode":"\n    // complete with only the system properties that start with \"sonar.\"\n    for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {\n      String key = entry.getKey().toString();\n      if (key.startsWith(\"sonar.\")) {\n        props.setProperty(key, entry.getValue().toString());\n      }\n    }\n    return props;\n  }\n\n  /**\n   * Convert strings \"-Dkey=value\" to properties\n   */\n  static Properties argumentsToProperties(String[] args) {\n    Properties props = new Properties();\n    for (String arg : args) {\n      if (!arg.startsWith(\"-D\") || !arg.contains(\"=\")) {\n        throw new IllegalArgumentException(String.format(\n          \"Command-line argument must start with -D, for example -Dsonar.jdbc.username=sonar. Got: %s\", arg));\n      }\n      String key = StringUtils.substringBefore(arg, \"=\").substring(2);\n      String value = StringUtils.substringAfter(arg, \"=\");\n      props.setProperty(key, value);\n    }\n    return props;\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":65,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/config/CommandLineParser.java#L37-L65","documentation":"SonarQube server's command-line argument parser converts JVM args of the form -Dkey=value into Java system properties. Any argument that does not start with '-D' or lacks an '=' separator is rejected with this IllegalArgumentException. It is a strict startup-time validation of CLI syntax.","triggerScenarios":"Calling CommandLine.argumentsToProperties (via props()) with an argument like 'sonar.jdbc.username=sonar' (missing -D prefix) or '-Dsonar.web.port' (missing =value).","commonSituations":"Hand-written start scripts passing flags without the -D prefix; quoting mistakes in shell scripts that split -D from the key; copy-pasting JVM flags like -Xmx or --foo into a properties-args list.","solutions":["Prefix the argument with -D, e.g. -Dsonar.jdbc.username=sonar","Ensure the argument contains an '=' separating key and value","Check shell quoting so '-Dkey=value' stays a single argument","Fix the calling script/wrapper that builds the argument array"],"exampleFix":"// before\nString[] args = {\"sonar.jdbc.username=sonar\"};\n// after\nString[] args = {\"-Dsonar.jdbc.username=sonar\"};","handlingStrategy":"validation","validationCode":"boolean isPropertyArg(String arg) { return arg != null && arg.startsWith(\"-D\") && arg.contains(\"=\"); }\n// filter before calling: Arrays.stream(args).filter(a -> { if (!isPropertyArg(a)) throw new IllegalArgumentException(a); return true; });","typeGuard":"static boolean isPropertyArg(String arg) { return arg != null && arg.startsWith(\"-D\") && arg.contains(\"=\"); }","tryCatchPattern":"try { Properties p = CommandLine.argumentsToProperties(args); } catch (IllegalArgumentException e) { log.error(\"Bad CLI arg: {}\", e.getMessage()); }","preventionTips":["Always prefix system properties with -D","Always include an = (empty value allowed as -Dkey=)","Quote arguments in shell scripts so they stay single tokens","Add a pre-start validation step for generated argument arrays"],"tags":["cli","arguments","validation","sonarqube"],"backgroundTag":"invalid-cli-argument","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}