{"record":{"id":"d42bc7e12a6a9541","repo":"apache/flink","slug":"the-input-args-contains-an-empty-argument","errorCode":null,"errorMessage":"The input ${args} contains an empty argument","messagePattern":"The input (.+?) contains an empty argument","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/Utils.java","lineNumber":361,"sourceCode":"     * @param args all given args.\n     * @param index the index of args to be parsed.\n     * @return the key of the given arg.\n     */\n    public static String getKeyFromArgs(String[] args, int index) {\n        String key;\n        if (args[index].startsWith(\"--\")) {\n            key = args[index].substring(2);\n        } else if (args[index].startsWith(\"-\")) {\n            key = args[index].substring(1);\n        } else {\n            throw new IllegalArgumentException(\n                    String.format(\n                            \"Error parsing arguments '%s' on '%s'. Please prefix keys with -- or -.\",\n                            Arrays.toString(args), args[index]));\n        }\n\n        if (key.isEmpty()) {\n            throw new IllegalArgumentException(\n                    \"The input \" + Arrays.toString(args) + \" contains an empty argument\");\n        }\n\n        return key;\n    }\n\n    /** Private constructor to prevent instantiation. */\n    private Utils() {\n        throw new RuntimeException();\n    }\n}\n","sourceCodeStart":343,"sourceCodeEnd":373,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/Utils.java#L343-L373","documentation":"After stripping the '-'/'--' prefix, getKeyFromArgs rejects tokens whose remaining key text is empty — i.e. the argument was just '-' or '--' with nothing after it. Such tokens cannot map to any option, so parsing aborts with the full args array in the message.","triggerScenarios":"Calling getKeyFromArgs with a token exactly \"--\" or \"-\" at the inspected index; commonly a trailing dash left by script concatenation ('--' + empty variable) or a typo.","commonSituations":"Shell scripts building args from possibly-empty environment variables (\"--${VAR}\" becomes \"--\"), stray trailing dashes in manually typed commands, stdin redirection symbols mistaken for args.","solutions":["Remove the bare '-'/'--' token from the command line.","In scripts, skip flag construction when the variable is empty: only append \"--key $VAR\" when VAR is set.","Use set -u / null checks so empty variables fail loudly at the source."],"exampleFix":"# before (VAR empty)\nARGS=\"--input ${INPUT:-}\"\n\n# after\nif [ -n \"${INPUT:-}\" ]; then ARGS=\"--input ${INPUT}\"; fi","handlingStrategy":"validation","validationCode":"if (token.equals(\"-\") || token.equals(\"--\")) throw new IllegalArgumentException(\"Empty argument token: \" + token);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never build flags by concatenating possibly-empty variables.","Skip optional flags entirely when their value is unset.","Use set -u in bash so empty variables fail at assignment."],"tags":["cli","arguments","parsing","shell"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}