{"record":{"id":"9d8fdbb199f81651","repo":"apache/cassandra","slug":"message-caller-provided-message-string","errorCode":null,"errorMessage":"message (caller-provided message string)","messagePattern":"message \\(caller-provided message string\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/RequestValidations.java","lineNumber":61,"sourceCode":" *      if (value < 0.0)\n *          throw RequestValidations.invalidRequest(\"negative value: %s\", toReadableText(value));\n *  </pre>\n * </p>\n */\npublic final class RequestValidations\n{\n    /**\n     * Checks that the specified expression is {@code true}. If not an {@code InvalidRequestException} will\n     * be thrown.\n     *\n     * @param expression the expression to test\n     * @param message the error message\n     * @throws InvalidRequestException if the specified expression is {@code false}.\n     */\n    public static void checkTrue(boolean expression, String message) throws InvalidRequestException\n    {\n        if (!expression)\n            throw invalidRequest(message);\n    }\n\n    /**\n     * Checks that the specified expression is <code>true</code>. If not an {@code InvalidRequestException} will\n     * be thrown.\n     *\n     * @param expression the expression to test\n     * @param messageTemplate the template used to build the error message\n     * @param messageArg the message argument\n     * @throws InvalidRequestException if the specified expression is {@code false}.\n     */\n    public static void checkTrue(boolean expression,\n                                 String messageTemplate,\n                                 Object messageArg) throws InvalidRequestException\n    {\n        if (!expression)\n            throw invalidRequest(messageTemplate, messageArg);\n    }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/RequestValidations.java#L43-L79","documentation":"RequestValidations.checkTrue is a CQL3 utility that throws an InvalidRequestException carrying the caller-supplied message when the given boolean expression is false. It is the shared guard used across statement validation. The message text is determined entirely by each call site, not by this method.","triggerScenarios":"Any CQL statement validation path that calls checkTrue(cond, msg) where the condition evaluates to false — e.g. malformed queries violating preconditions checked during parsing/prepare/execute of statements.","commonSituations":"Developers hitting it indirectly via a malformed CQL query (bad TTL, invalid options, wrong argument combinations); contributors calling checkTrue with a condition that can legitimately be false on user input.","solutions":["Read the exception message; it names the exact violated precondition from the failing checkTrue call site","Fix the CQL statement so the validated condition holds","If raised from your own code, ensure the caller checks the condition before invoking the API"],"exampleFix":"// before\ncheckTrue(rowCount > 0, \"expected at least one row\"); // throws when empty\n// after\nif (rowCount > 0) checkTrue(rowCount > 0, \"expected at least one row\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { session.execute(query); }\ncatch (InvalidRequestException e) { log.error(\"Invalid request: {}\", e.getMessage()); throw new QueryValidationException(e); }","preventionTips":["Validate CQL statements against schema before executing","Keep statement construction type-safe with the driver's query builder","Test queries against a local single-node cluster"],"tags":["cql","validation","invalid-request"],"backgroundTag":"invalid-argument-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}