stanfordnlp/CoreNLP · error · RuntimeException

Invalid dictionary line

Error message

Invalid dictionary line: ${line}

What it means

When load() reads a saved dictionary file, each line must tokenize into exactly 3 fields (word, index, count). If a line has a different field count, load() throws this RuntimeException, indicating the dictionary file is malformed.

Solutions

  1. Open the dictionary file at the reported location and fix or remove the malformed line.
  2. Regenerate the dictionary file from source data via save() instead of editing it by hand.
  3. Check that the file is whitespace-tokenizable with SimpleTokenize: quote/escape spaces in words or use the format the saver emits.
  4. Confirm you are loading the file produced by the same format version.

Example fix

// before (bad line)
Paris 12
// after
Paris 12 5
Defensive patterns

Strategy: validation

Validate before calling

for (String line : Files.readAllLines(path)) {
  String[] t = line.trim().split("\\s+");
  if (t.length != 3) throw new IllegalStateException("bad dictionary line: " + line);
}

Try / catch

try { dict.load(path, prefix); } catch (RuntimeException e) { logger.severe("malformed dictionary " + prefix + ": " + e.getMessage()); throw e; }

Prevention

When it happens

Trigger: load(path, prefix) encountering a dictionary line where SimpleTokenize.tokenize yields != 3 tokens — e.g. a word containing an unquoted space, an edited/truncated file, or a manually written dictionary entry missing the index or count column.

Common situations: Hand-edited .dict files, files saved by a different tool or format version, copy-paste corruption, CRLF/encoding issues that merge or split fields.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/253b22fe90da0dd9. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/machinereading/common/StringDictionary.java:169

  public void clear() {
    mDict.clear();
    mInverse.clear();
  }

  public Set<String> keySet() {
    return mDict.keySet();
  }

  /** Loads all saved dictionary entries from disk */
  public void load(String path, String prefix) throws java.io.IOException {

    String fileName = path + java.io.File.separator + prefix + "." + mName;
    try (BufferedReader is = IOUtils.readerFromString(fileName)) {

      for (String line; (line = is.readLine()) != null; ) {
        ArrayList<String> tokens = SimpleTokenize.tokenize(line);
        if (tokens.size() != 3) {
          throw new RuntimeException("Invalid dictionary line: " + line);
        }
        int index = Integer.parseInt(tokens.get(1));
        int count = Integer.parseInt(tokens.get(2));
        if (index < 0 || count <= 0) {
          throw new RuntimeException("Invalid dictionary line: " + line);
        }

        IndexAndCount ic = new IndexAndCount(index, count);
        mDict.put(tokens.get(0), ic);
        mInverse.put(Integer.valueOf(index), tokens.get(0));
      }

      log.info("Loaded " + mDict.size() + " entries for dictionary \"" + mName + "\".");
    }
  }

  public java.util.Set<String> keys() {
    return mDict.keySet();

View on GitHub (pinned to 1b7edd19c4)