{"record":{"id":"3f143a9948eb2f91","repo":"apache/cassandra","slug":"message-caller-provided-message-string-checkcont","errorCode":null,"errorMessage":"message (caller-provided message string, checkContainsNoDuplicates)","messagePattern":"message \\(caller-provided message string, checkContainsNoDuplicates\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/RequestValidations.java","lineNumber":171,"sourceCode":"                                                               Object arg1,\n                                                               Object arg2)\n                                                               throws InvalidRequestException\n    {\n        checkTrue(!collection.isEmpty(), messageTemplate, arg1, arg2);\n        return collection;\n    }\n\n    /**\n     * Checks that the specified list does not contains duplicates.\n     *\n     * @param list the list to test\n     * @param message the error message\n     * @throws InvalidRequestException if the specified list contains duplicates.\n     */\n    public static void checkContainsNoDuplicates(List<?> list, String message) throws InvalidRequestException\n    {\n        if (new HashSet<>(list).size() != list.size())\n            throw invalidRequest(message);\n    }\n\n    /**\n     * Checks that the specified list contains only the specified elements.\n     *\n     * @param list the list to test\n     * @param expectedElements the expected elements\n     * @param message the error message\n     * @throws InvalidRequestException if the specified list contains duplicates.\n     */\n    public static <E> void checkContainsOnly(List<E> list,\n                                             List<E> expectedElements,\n                                             String message) throws InvalidRequestException\n    {\n        List<E> copy = new ArrayList<>(list);\n        copy.removeAll(expectedElements);\n        if (!copy.isEmpty())\n            throw invalidRequest(message);","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/RequestValidations.java#L153-L189","documentation":"RequestValidations.checkContainsNoDuplicates(List<?> list, String message) throws InvalidRequestException if the list contains duplicate elements (detected by comparing HashSet size to list size). Used during CQL statement validation to reject duplicate identifiers in user-supplied lists.","triggerScenarios":"Any statement whose validation passes a user-supplied list (e.g. column names in a restriction, selection, or definition) that contains the same element more than once, with a call-site-provided message.","commonSituations":"Listing the same column twice in a clause, e.g. duplicate column in SELECT restrictions, PRIMARY KEY definitions, or CREATE statements with repeated identifiers.","solutions":["Remove duplicate entries from the offending identifier list in the query","If generated dynamically, deduplicate the list before building the statement","Check for case variations that normalize to the same identifier (unquoted names are lowercased)"],"exampleFix":"// before\nSELECT a, b, a FROM ks.t WHERE ...; -- duplicate 'a'\n// after\nSELECT a, b FROM ks.t WHERE ...;","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (String col : columns) { if (!seen.add(col.toLowerCase())) throw new IllegalArgumentException(\"duplicate column \" + col); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate column/identifier lists before building queries","Normalize identifier case before comparisons","When building SQL-like strings programmatically, use ordered sets"],"tags":["cql","validation","duplicates"],"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-17T15:17:12.973Z"}