public void update() {
            if (count == entriesGeneratedAtCount) { // Already up to date
                return;
            }
            size = ngrams.size();
            final int numChars = (length + 2) * size;
            if (entries == null || entries.length < numChars) {
                entries = new char[numChars];
            }
            int pos = 0;
            for (Map.Entry<String, Counter> entry : getSortedNgrams()) {
                for (int l = 0; l < length; l++) {
                    entries[pos + l] = entry.getKey().charAt(l);
                }
                entries[pos + length] = (char) (entry.getValue().count / 65536); // Upper 16 bit
                entries[pos + length + 1] = (char) (entry.getValue().count % 65536); // lower 16 bit
                pos += length + 2;
            }
            entriesGeneratedAtCount = count;
        }
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