{"record":{"id":"9953a47bfc213c9a","repo":"apache/cassandra","slug":"dictionary-file-s-is-not-correctly-sorted-for-cas","errorCode":null,"errorMessage":"Dictionary file %s is not correctly sorted for case-sensitive comparator according to String's compareTo contract.","messagePattern":"Dictionary file (.+?) is not correctly sorted for case-sensitive comparator according to String's compareTo contract\\.","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/guardrails/CassandraPasswordValidator.java","lineNumber":497,"sourceCode":"\n    @Override\n    public DictionaryRule initializeDictionaryRule(CassandraPasswordConfiguration configuration)\n    {\n        if (configuration.dictionary == null)\n            return null;\n\n        try\n        {\n            RandomAccessFile raf = new RandomAccessFile(configuration.dictionary, \"r\");\n            FileWordList fileWordList = new FileWordList(raf, true, 100);\n            WordListDictionary wordListDictionary = new WordListDictionary(fileWordList);\n            return new DictionaryRule(wordListDictionary);\n        }\n        catch (IllegalArgumentException ex)\n        {\n            // improve message a little bit\n            if (\"File is not sorted correctly for this comparator\".equals(ex.getMessage()))\n                throw new ConfigurationException(\"Dictionary file \" + configuration.dictionary + \" is not correctly \" +\n                                                 \"sorted for case-sensitive comparator according to String's \" +\n                                                 \"compareTo contract.\");\n            else\n                throw new ConfigurationException(ex.getMessage());\n        }\n        catch (IOException ex)\n        {\n            throw new ConfigurationException(ex.getMessage());\n        }\n    }\n}\n","sourceCodeStart":479,"sourceCodeEnd":509,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/guardrails/CassandraPasswordValidator.java#L479-L509","documentation":"The dictionary rule uses a binary-search word list which must be sorted according to String's compareTo (case-sensitive) order. When loading the dictionary produces an IllegalArgumentException with the message 'File is not sorted correctly for this comparator', Cassandra rethrows it as a ConfigurationException with this clearer message at initializeDictionaryRule time.","triggerScenarios":"Configuring cassandra.password_validator.dictionary with a word list that is not strictly sorted by Unicode code-point order (e.g. sorted case-insensitively, or containing out-of-order entries).","commonSituations":"Human-edited word lists appended out of order; word lists generated with `sort` under a locale that reorders case differently from Java's compareTo; concatenated lists from multiple sources.","solutions":["Re-sort the dictionary with byte/code-point ordering, e.g. `LC_ALL=C sort -u <wordlist> > <wordlist>.sorted` and point the config at it","Verify sortedness programmatically with a small Java/Python check comparing adjacent entries per String.compareTo semantics","Remove duplicate or unsorted appended entries and re-validate"],"exampleFix":"// before\napple\nBanana  (uppercase B sorts before lowercase a in compareTo)\n// after\nLC_ALL=C sort -u wordlist.txt -o wordlist.txt\n# yields: Banana\napple","handlingStrategy":"validation","validationCode":"import java.util.*;\nList<String> lines = java.nio.file.Files.readAllLines(java.nio.file.Path.of(dictPath));\nfor (int i = 1; i < lines.size(); i++)\n    if (lines.get(i-1).compareTo(lines.get(i)) > 0)\n        throw new IllegalStateException(\"Not compareTo-sorted at line \" + (i+1));","typeGuard":null,"tryCatchPattern":"try {\n    initializeValidator(config);\n} catch (ConfigurationException e) {\n    if (e.getMessage().contains(\"not correctly sorted\")) {\n        logger.error(\"Re-sort dictionary with LC_ALL=C sort -u: {}\", e.getMessage());\n    }\n}","preventionTips":["Always generate word lists with `LC_ALL=C sort -u`, not locale-dependent sort","Run a sortedness check in your deploy pipeline before distributing the file","Document that the dictionary must follow String.compareTo order"],"tags":["configuration","guardrails","dictionary","sorting"],"backgroundTag":"invalid-config-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"}