private List<Map.Entry<String, Counter>> getSortedNgrams() {
            List<Map.Entry<String, Counter>> entries =
                    new ArrayList<>(ngrams.size());
            entries.addAll(ngrams.entrySet());
            entries.sort(Map.Entry.comparingByKey());
            return entries;
        }
Ensure that the entries array is in sync with the ngrams.
tika-langdetect/tika-langdetect-tika/src/main/java/org/apache/tika/langdetect/tika/LanguageProfile.java