apache/cassandra · error · IllegalArgumentException

Invalid value ; must match pattern

Error message

Invalid value ; must match pattern 

What it means

OptionSimple validates its value against an optional regex Pattern via this value adapter. When the user-supplied string does not fully match the pattern, apply() throws an IllegalArgumentException naming both the offending value and the required pattern.

Solutions

  1. Read the pattern from the error message and fix the value to match it exactly (matches() requires the WHOLE string to match).
  2. Remove stray whitespace, quotes, or shell-escaped characters from the argument.
  3. Check the option's documented format in 'cassandra-stress help' and use an example value verbatim.
  4. If you control the option definition, loosen or correct the valuePattern regex if it is overly restrictive.

Example fix

// before (shell)
cassandra-stress write n=1M -rate "threads>=4"  # fails pattern
// after
cassandra-stress write n=1M -rate threads=4
Defensive patterns

Strategy: validation

Validate before calling

Pattern p = Pattern.compile(valuePattern);
if (!p.matcher(value).matches()) throw new IllegalArgumentException("value must match " + valuePattern);

Try / catch

try { /* parse args */ } catch (IllegalArgumentException e) { if (e.getMessage().contains("must match pattern")) { /* surface the pattern to the user and re-prompt */ } else throw e; }

Prevention

When it happens

Trigger: Any cassandra-stress option value passed to OptionSimple where the value fails Pattern.matcher(s).matches(), typically triggered from inflate() when parsing CLI arguments — e.g. a non-numeric value where the pattern demands digits, or a value with illegal characters.

Common situations: Typing 'rate=1000/sec' when only plain integers are accepted; quoting values so quotes become part of the string; shell expansion mangling a value (e.g. unescaped '*'); using a comma or space where the pattern expects a single token.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/22607d51187027a9. Report an issue: GitHub.

Appendix: source

Thrown at tools/stress/src/org/apache/cassandra/stress/settings/OptionSimple.java:55

    final String displayPrefix;
    private final Pattern matchPrefix;
    private final String defaultValue;
    private final Function<String, String> valueAdapter;
    private final String description;
    private final boolean required;
    private String value;

    private static final class ValueMatcher implements Function<String, String>, Serializable
    {
        final Pattern pattern;
        private ValueMatcher(Pattern pattern)
        {
            this.pattern = pattern;
        }
        public String apply(String s)
        {
            if (!pattern.matcher(s).matches())
                throw new IllegalArgumentException("Invalid value " + s + "; must match pattern " + pattern);
            return s;
        }
    }

    public OptionSimple(String prefix, String valuePattern, String defaultValue, String description, boolean required)
    {
        this(prefix, Pattern.compile(Pattern.quote(prefix), Pattern.CASE_INSENSITIVE),
             Pattern.compile(valuePattern, Pattern.CASE_INSENSITIVE), defaultValue, description, required);
    }

    public OptionSimple(String prefix, Function<String, String> valueAdapter, String defaultValue, String description, boolean required)
    {
        this(prefix, Pattern.compile(Pattern.quote(prefix), Pattern.CASE_INSENSITIVE), valueAdapter, defaultValue, description, required);
    }

    public OptionSimple(String displayPrefix, Pattern matchPrefix, Pattern valuePattern, String defaultValue, String description, boolean required)
    {
        this(displayPrefix, matchPrefix, new ValueMatcher(valuePattern), defaultValue, description, required);

View on GitHub (pinned to 88fd0f6a0e)