apache/flink · error · IllegalArgumentException

The input ${args} contains an empty argument

Error message

The input ${args} contains an empty argument

What it means

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.

Source

Thrown at flink-core/src/main/java/org/apache/flink/util/Utils.java:361

     * @param args all given args.
     * @param index the index of args to be parsed.
     * @return the key of the given arg.
     */
    public static String getKeyFromArgs(String[] args, int index) {
        String key;
        if (args[index].startsWith("--")) {
            key = args[index].substring(2);
        } else if (args[index].startsWith("-")) {
            key = args[index].substring(1);
        } else {
            throw new IllegalArgumentException(
                    String.format(
                            "Error parsing arguments '%s' on '%s'. Please prefix keys with -- or -.",
                            Arrays.toString(args), args[index]));
        }

        if (key.isEmpty()) {
            throw new IllegalArgumentException(
                    "The input " + Arrays.toString(args) + " contains an empty argument");
        }

        return key;
    }

    /** Private constructor to prevent instantiation. */
    private Utils() {
        throw new RuntimeException();
    }
}

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Remove the bare '-'/'--' token from the command line.
  2. In scripts, skip flag construction when the variable is empty: only append "--key $VAR" when VAR is set.
  3. Use set -u / null checks so empty variables fail loudly at the source.

Example fix

# before (VAR empty)
ARGS="--input ${INPUT:-}"

# after
if [ -n "${INPUT:-}" ]; then ARGS="--input ${INPUT}"; fi
Defensive patterns

Strategy: validation

Validate before calling

if (token.equals("-") || token.equals("--")) throw new IllegalArgumentException("Empty argument token: " + token);

Prevention

When it happens

Trigger: Calling getKeyFromArgs with a token exactly "--" or "-" at the inspected index; commonly a trailing dash left by script concatenation ('--' + empty variable) or a typo.

Common situations: Shell scripts building args from possibly-empty environment variables ("--${VAR}" becomes "--"), stray trailing dashes in manually typed commands, stdin redirection symbols mistaken for args.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/d42bc7e12a6a9541. Report an issue: GitHub.