{"record":{"id":"9cb8f2fdaed11db4","repo":"apache/cassandra","slug":"like-value-can-t-be-empty","errorCode":null,"errorMessage":"LIKE value can't be empty.","messagePattern":"LIKE value can't be empty\\.","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/LikePattern.java","lineNumber":110,"sourceCode":"            else\n            {\n                kind = Kind.PREFIX;\n            }\n        }\n        else if (ByteBufferUtil.startsWith(value, WILDCARD))\n        {\n            kind = Kind.SUFFIX;\n            beginIndex += 1;\n            endIndex += 1;\n        }\n        else\n        {\n            kind = Kind.MATCHES;\n            endIndex += 1;\n        }\n\n        if (endIndex == 0 || beginIndex == endIndex)\n            throw invalidRequest(\"LIKE value can't be empty.\");\n\n        ByteBuffer newValue = value.duplicate();\n        newValue.position(beginIndex);\n        newValue.limit(endIndex);\n        // Checking if we still have WILDCARD in value and if yes return error.\n        if (ByteBufferUtil.contains(newValue, WILDCARD))\n            throw invalidRequest(\"LIKE value can't contain a % other than at the start and/or end\");\n        return new LikePattern(kind, newValue);\n    }\n}\n","sourceCodeStart":92,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/LikePattern.java#L92-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"User-supplied search strings passed straight into CQL from an application; empty search boxes submitted to a dashboard that builds LIKE clauses dynamically.","solutions":["Check the pattern is non-empty before issuing the query; fall back to an EQ or no restriction for empty input","Strip or reject inputs consisting solely of % wildcards at the application layer","Use a startsWith-style pattern (e.g. 'abc%') instead of a bare wildcard"],"exampleFix":"// before\nString cql = \"SELECT * FROM t WHERE name LIKE '\" + userInput + \"'\";\n// after\nif (userInput == null || userInput.replace(\"%\", \"\").isEmpty()) throw new IllegalArgumentException(\"search pattern must contain text\");\nString cql = \"SELECT * FROM t WHERE name LIKE '\" + userInput + \"'\";","handlingStrategy":"validation","validationCode":"function isValidLikePattern(p) {\n  return typeof p === 'string' && p.replace(/%/g, '').length > 0;\n}\nif (!isValidLikePattern(userInput)) throw new Error('LIKE pattern must contain non-wildcard text');","typeGuard":"function isNonEmptyCorePattern(p) { return typeof p === 'string' && p.replace(/%/g, '').length > 0; }","tryCatchPattern":null,"preventionTips":["Sanitize search input at the UI layer before building CQL","Never concatenate raw user input into LIKE clauses without checks","Treat empty/blank searches as 'no filter' rather than emitting LIKE '%'"],"tags":["cql","like-operator","validation"],"backgroundTag":"empty-required-field","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"}