{"record":{"id":"22607d51187027a9","repo":"apache/cassandra","slug":"invalid-value-must-match-pattern","errorCode":null,"errorMessage":"Invalid value ; must match pattern ","messagePattern":"Invalid value ; must match pattern ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/stress/settings/OptionSimple.java","lineNumber":55,"sourceCode":"    final String displayPrefix;\n    private final Pattern matchPrefix;\n    private final String defaultValue;\n    private final Function<String, String> valueAdapter;\n    private final String description;\n    private final boolean required;\n    private String value;\n\n    private static final class ValueMatcher implements Function<String, String>, Serializable\n    {\n        final Pattern pattern;\n        private ValueMatcher(Pattern pattern)\n        {\n            this.pattern = pattern;\n        }\n        public String apply(String s)\n        {\n            if (!pattern.matcher(s).matches())\n                throw new IllegalArgumentException(\"Invalid value \" + s + \"; must match pattern \" + pattern);\n            return s;\n        }\n    }\n\n    public OptionSimple(String prefix, String valuePattern, String defaultValue, String description, boolean required)\n    {\n        this(prefix, Pattern.compile(Pattern.quote(prefix), Pattern.CASE_INSENSITIVE),\n             Pattern.compile(valuePattern, Pattern.CASE_INSENSITIVE), defaultValue, description, required);\n    }\n\n    public OptionSimple(String prefix, Function<String, String> valueAdapter, String defaultValue, String description, boolean required)\n    {\n        this(prefix, Pattern.compile(Pattern.quote(prefix), Pattern.CASE_INSENSITIVE), valueAdapter, defaultValue, description, required);\n    }\n\n    public OptionSimple(String displayPrefix, Pattern matchPrefix, Pattern valuePattern, String defaultValue, String description, boolean required)\n    {\n        this(displayPrefix, matchPrefix, new ValueMatcher(valuePattern), defaultValue, description, required);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/stress/settings/OptionSimple.java#L37-L73","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the pattern from the error message and fix the value to match it exactly (matches() requires the WHOLE string to match).","Remove stray whitespace, quotes, or shell-escaped characters from the argument.","Check the option's documented format in 'cassandra-stress help' and use an example value verbatim.","If you control the option definition, loosen or correct the valuePattern regex if it is overly restrictive."],"exampleFix":"// before (shell)\ncassandra-stress write n=1M -rate \"threads>=4\"  # fails pattern\n// after\ncassandra-stress write n=1M -rate threads=4","handlingStrategy":"validation","validationCode":"Pattern p = Pattern.compile(valuePattern);\nif (!p.matcher(value).matches()) throw new IllegalArgumentException(\"value must match \" + valuePattern);","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Quote CLI values carefully to keep shell noise out of the string.","Test option strings with 'cassandra-stress help' examples first.","Remember matches() requires the entire value to match, not just a prefix."],"tags":["cli","validation","regex"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}