apache/cassandra · error · InvalidRequestException

LIKE value can't be empty.

Error message

LIKE value can't be empty.

What it means

The LIKE operator requires a non-empty pattern once the leading/trailing % wildcards are stripped. LikePattern.parse throws this when the value consists only of wildcards or is empty, because matching against an empty core pattern is meaningless.

Solutions

  1. Check the pattern is non-empty before issuing the query; fall back to an EQ or no restriction for empty input
  2. Strip or reject inputs consisting solely of % wildcards at the application layer
  3. Use a startsWith-style pattern (e.g. 'abc%') instead of a bare wildcard

Example fix

// before
String cql = "SELECT * FROM t WHERE name LIKE '" + userInput + "'";
// after
if (userInput == null || userInput.replace("%", "").isEmpty()) throw new IllegalArgumentException("search pattern must contain text");
String cql = "SELECT * FROM t WHERE name LIKE '" + userInput + "'";
Defensive patterns

Strategy: validation

Validate before calling

function isValidLikePattern(p) {
  return typeof p === 'string' && p.replace(/%/g, '').length > 0;
}
if (!isValidLikePattern(userInput)) throw new Error('LIKE pattern must contain non-wildcard text');

Type guard

function isNonEmptyCorePattern(p) { return typeof p === 'string' && p.replace(/%/g, '').length > 0; }

Prevention

When it happens

Trigger: Statements like col LIKE '' or col LIKE '%' or col LIKE '%%' reach LikePattern.parse: after removing the leading/trailing WILDCARD chars, beginIndex == endIndex (or endIndex == 0), so invalidRequest is thrown.

Common situations: User-supplied search strings passed straight into CQL from an application; empty search boxes submitted to a dashboard that builds LIKE clauses dynamically.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/restrictions/LikePattern.java:110

            else
            {
                kind = Kind.PREFIX;
            }
        }
        else if (ByteBufferUtil.startsWith(value, WILDCARD))
        {
            kind = Kind.SUFFIX;
            beginIndex += 1;
            endIndex += 1;
        }
        else
        {
            kind = Kind.MATCHES;
            endIndex += 1;
        }

        if (endIndex == 0 || beginIndex == endIndex)
            throw invalidRequest("LIKE value can't be empty.");

        ByteBuffer newValue = value.duplicate();
        newValue.position(beginIndex);
        newValue.limit(endIndex);
        // Checking if we still have WILDCARD in value and if yes return error.
        if (ByteBufferUtil.contains(newValue, WILDCARD))
            throw invalidRequest("LIKE value can't contain a % other than at the start and/or end");
        return new LikePattern(kind, newValue);
    }
}

View on GitHub (pinned to 88fd0f6a0e)