{"record":{"id":"00aa5c95c859aba7","repo":"eclipse-vertx/vert.x","slug":"invalid-argname-arg","errorCode":null,"errorMessage":"Invalid ${argName}: ${arg}","messagePattern":"Invalid (.+?): (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/impl/Args.java","lineNumber":51,"sourceCode":"        if (currentKey != null) {\n          map.put(currentKey, arg);\n          currentKey = null;\n        }\n      }\n    }\n    if (currentKey != null) {\n      map.put(currentKey, \"\");\n    }\n  }\n\n  public int getInt(String argName) {\n    String arg = map.get(argName);\n    int val;\n    if (arg != null) {\n      try {\n        val = Integer.parseInt(arg.trim());\n      } catch (NumberFormatException e) {\n        throw new IllegalArgumentException(\"Invalid \" + argName + \": \" + arg);\n      }\n    } else {\n      val = -1;\n    }\n    return val;\n  }\n}\n","sourceCodeStart":33,"sourceCodeEnd":59,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/impl/Args.java#L33-L59","documentation":"Args.getInt parses a named string argument from a map into an int. When the value exists but cannot be parsed by Integer.parseInt, an IllegalArgumentException('Invalid <name>: <value>') is thrown. Missing values silently return -1 instead of throwing.","triggerScenarios":"Calling getInt(argName) on an Args/option map whose stored value is a non-numeric string (e.g. 'abc', '', '12x') for options like -cluster-port or -instances.","commonSituations":"Launcher CLI options passed via -D or command line with typos; quoting issues in scripts leaving empty or whitespace-polluted values; user-supplied config files where a port was meant but text was entered.","solutions":["Check the value printed in the message and fix the argument so it is a valid integer (trimmed decimal digits)","Verify how the argument map is populated (launch script, system property, JSON) and correct the source value","If a missing value is expected, note getInt returns -1 and validate the -1 case at the call site instead of relying on parsing"],"exampleFix":"// before\nvertx.runVerticle(MainVerticle.class, new DeploymentOptions().setInstances(Integer.parseInt(args.value(\"-instances\"))));\n// after\nString raw = args.value(\"-instances\");\nif (raw == null || !raw.trim().matches(\"\\\\d+\")) {\n  throw new IllegalArgumentException(\"-instances must be an integer, got: \" + raw);\n}","handlingStrategy":"validation","validationCode":"if (raw != null && !raw.trim().matches(\"-?\\\\d+\")) throw new IllegalArgumentException(\"-instances must be an integer, got: \" + raw);","typeGuard":"boolean isInt(String s){ return s != null && s.trim().matches(\"-?\\\\d+\"); }","tryCatchPattern":null,"preventionTips":["Validate all CLI/config numeric fields at startup with a schema or regex","Trim and normalize values before parsing","Treat -1 from getInt as 'absent' and handle explicitly"],"tags":["arguments","parsing","cli","illegal-argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}