{"record":{"id":"6058c24d012e17c0","repo":"apache/cassandra","slug":"value-does-match-regular-expression-s","errorCode":null,"errorMessage":"Value does match regular expression %s","messagePattern":"Value does match regular expression (.+?)","errorType":"validation","errorClass":"ConstraintViolationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/constraints/RegexpConstraint.java","lineNumber":64,"sourceCode":"    {\n        super(FUNCTION_NAME, args);\n    }\n\n    @Override\n    protected void internalEvaluate(AbstractType<?> valueType, Operator relationType, String regexp, ByteBuffer columnValue)\n    {\n        assert pattern != null;\n        Matcher matcher = pattern.matcher(valueType.getString(columnValue));\n\n        switch (relationType)\n        {\n            case EQ:\n                if (!matcher.matches())\n                    throw new ConstraintViolationException(format(\"Value does not match regular expression %s\", regexp));\n                break;\n            case NEQ:\n                if (matcher.matches())\n                    throw new ConstraintViolationException(format(\"Value does match regular expression %s\", regexp));\n                break;\n            default:\n                throw new IllegalStateException(\"Unsupported operator: \" + relationType);\n        }\n    }\n\n    @Override\n    public List<AbstractType<?>> getSupportedTypes()\n    {\n        return SUPPORTED_TYPES;\n    }\n\n    @Override\n    public List<Operator> getSupportedOperators()\n    {\n        return ALLOWED_FUNCTION_OPERATORS;\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/constraints/RegexpConstraint.java#L46-L82","documentation":"Thrown by RegexpConstraint.internalEvaluate when the relationType is NEQ and the column value DOES match the declared regular expression. This is the inverse-check branch: the constraint forbids values matching the pattern, so a matching value raises ConstraintViolationException.","triggerScenarios":"INSERT/UPDATE of a column with a negative regexp constraint (NEQ) where the value matches the forbidden pattern.","commonSituations":"Blocking reserved prefixes or forbidden formats (e.g. disallow 'admin:*' usernames, disallow legacy id formats) but legacy data or unvalidated input still matches the forbidden pattern.","solutions":["Change the value so it no longer matches the forbidden pattern.","If matching values should be allowed now, ALTER the table to drop or invert the constraint.","Add pre-write validation in the application mirroring the forbidden pattern to fail fast with a clearer error."],"exampleFix":"// constraint forbids names starting with 'system:'\n// before: INSERT INTO t (name) VALUES ('system:root'); -- rejected\n// after\nINSERT INTO t (name) VALUES ('svc:root');","handlingStrategy":"validation","validationCode":"// Java: ensure value does NOT match the forbidden pattern before writing\nif (java.util.regex.Pattern.compile(\"^system:.*\").matcher(name).matches())\n    throw new IllegalArgumentException(\"name uses reserved prefix\");","typeGuard":null,"tryCatchPattern":"catch (ConstraintViolationException e) { log.warn(\"value matched forbidden pattern: {}\", e.getMessage()); }","preventionTips":["Document which patterns are forbidden for constrained columns.","Test legacy data against negative constraints before enabling them.","Centralize forbidden-pattern checks in the data-access layer."],"tags":["cassandra","cql","regexp","constraint-violation"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}