apache/cassandra · error · ConstraintViolationException

Value does match regular expression %s

Error message

Value does match regular expression %s

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/constraints/RegexpConstraint.java:64

    {
        super(FUNCTION_NAME, args);
    }

    @Override
    protected void internalEvaluate(AbstractType<?> valueType, Operator relationType, String regexp, ByteBuffer columnValue)
    {
        assert pattern != null;
        Matcher matcher = pattern.matcher(valueType.getString(columnValue));

        switch (relationType)
        {
            case EQ:
                if (!matcher.matches())
                    throw new ConstraintViolationException(format("Value does not match regular expression %s", regexp));
                break;
            case NEQ:
                if (matcher.matches())
                    throw new ConstraintViolationException(format("Value does match regular expression %s", regexp));
                break;
            default:
                throw new IllegalStateException("Unsupported operator: " + relationType);
        }
    }

    @Override
    public List<AbstractType<?>> getSupportedTypes()
    {
        return SUPPORTED_TYPES;
    }

    @Override
    public List<Operator> getSupportedOperators()
    {
        return ALLOWED_FUNCTION_OPERATORS;
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Change the value so it no longer matches the forbidden pattern.
  2. If matching values should be allowed now, ALTER the table to drop or invert the constraint.
  3. Add pre-write validation in the application mirroring the forbidden pattern to fail fast with a clearer error.

Example fix

// constraint forbids names starting with 'system:'
// before: INSERT INTO t (name) VALUES ('system:root'); -- rejected
// after
INSERT INTO t (name) VALUES ('svc:root');
Defensive patterns

Strategy: validation

Validate before calling

// Java: ensure value does NOT match the forbidden pattern before writing
if (java.util.regex.Pattern.compile("^system:.*").matcher(name).matches())
    throw new IllegalArgumentException("name uses reserved prefix");

Try / catch

catch (ConstraintViolationException e) { log.warn("value matched forbidden pattern: {}", e.getMessage()); }

Prevention

When it happens

Trigger: INSERT/UPDATE of a column with a negative regexp constraint (NEQ) where the value matches the forbidden pattern.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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