apache/cassandra · error · ConfigurationException

Dictionary file is not correctly sorted for case-sensitive…

Error message

Dictionary file %s is not correctly sorted for case-sensitive comparator according to String's compareTo contract.

What it means

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.

Solutions

  1. 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
  2. Verify sortedness programmatically with a small Java/Python check comparing adjacent entries per String.compareTo semantics
  3. Remove duplicate or unsorted appended entries and re-validate

Example fix

// before
apple
Banana  (uppercase B sorts before lowercase a in compareTo)
// after
LC_ALL=C sort -u wordlist.txt -o wordlist.txt
# yields: Banana
apple
Defensive patterns

Strategy: validation

Validate before calling

import java.util.*;
List<String> lines = java.nio.file.Files.readAllLines(java.nio.file.Path.of(dictPath));
for (int i = 1; i < lines.size(); i++)
    if (lines.get(i-1).compareTo(lines.get(i)) > 0)
        throw new IllegalStateException("Not compareTo-sorted at line " + (i+1));

Try / catch

try {
    initializeValidator(config);
} catch (ConfigurationException e) {
    if (e.getMessage().contains("not correctly sorted")) {
        logger.error("Re-sort dictionary with LC_ALL=C sort -u: {}", e.getMessage());
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/java/org/apache/cassandra/db/guardrails/CassandraPasswordValidator.java:497

    @Override
    public DictionaryRule initializeDictionaryRule(CassandraPasswordConfiguration configuration)
    {
        if (configuration.dictionary == null)
            return null;

        try
        {
            RandomAccessFile raf = new RandomAccessFile(configuration.dictionary, "r");
            FileWordList fileWordList = new FileWordList(raf, true, 100);
            WordListDictionary wordListDictionary = new WordListDictionary(fileWordList);
            return new DictionaryRule(wordListDictionary);
        }
        catch (IllegalArgumentException ex)
        {
            // improve message a little bit
            if ("File is not sorted correctly for this comparator".equals(ex.getMessage()))
                throw new ConfigurationException("Dictionary file " + configuration.dictionary + " is not correctly " +
                                                 "sorted for case-sensitive comparator according to String's " +
                                                 "compareTo contract.");
            else
                throw new ConfigurationException(ex.getMessage());
        }
        catch (IOException ex)
        {
            throw new ConfigurationException(ex.getMessage());
        }
    }
}

View on GitHub (pinned to 88fd0f6a0e)