stanfordnlp/CoreNLP · critical · RuntimeException

Error reading from " + this.filename

Error message

Error reading from " + this.filename

What it means

readNextDocument wraps all exceptions encountered while parsing the next serialized annotation into RuntimeException with message 'Error reading from <filename>', chaining the original cause. It signals a malformed or truncated input file rather than a normal end-of-iteration.

Solutions

  1. Inspect the chained cause (ex.getCause()) to see the actual parse/IO failure
  2. Validate the file is complete and regenerated by the same serializer that produced it (e.g. re-run CoreNLP output)
  3. Verify the extension matches the actual content format (.jsonl vs .proto)
  4. Check file permissions and disk integrity; test reading with a fresh small file

Example fix

// before
AnnotationIterator it = new AnnotationIterator("partial.jsonl");
// after
// regenerate/complete the file first, then:
AnnotationIterator it = new AnnotationIterator("complete.jsonl");
Defensive patterns

Strategy: try-catch

Validate before calling

File f = new File(filename);
if (!f.isFile() || f.length() == 0)
  throw new IllegalArgumentException("Missing/empty annotation file: " + filename);

Try / catch

try {
  iterateAll(it);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("Error reading from")) {
    log.error("Corrupt input " + filename + ": " + e.getCause());
  } else throw e;
}

Prevention

When it happens

Trigger: Corrupt or truncated .jsonl/.proto file, bytes not matching the chosen serializer (e.g. JSON lines fed to the proto path), IO failure mid-file, deserialization exceptions thrown by the AnnotationSerializer.

Common situations: Files cut short by interrupted jobs, hand-edited JSONL, wrong extension causing wrong serializer selection, encoding corruption, partial downloads.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/AnnotationIterator.java:105

                }
            } else if (format.equals("json")) {
                Annotation annotation = readJsonDocument(IOUtils.slurpReader(this.br));
                this.close();
                docCnt++;
                return annotation;
            } else if (format.equals("jsonl")) {
                String line = br.readLine();
                while (line != null) {
                    line = line.trim();
                    if (!line.isEmpty()) {
                        Annotation annotation = readJsonDocument(line);
                        docCnt++;
                        return annotation;
                    }
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException("Error reading from " + this.filename, ex);
        }
        return null;
    }

    public int getDocCnt() {
        return docCnt;
    }

    public void close() {
        if (br != null) {
            IOUtils.closeIgnoringExceptions(br);
            br = null;
        }
        if (input != null) {
            IOUtils.closeIgnoringExceptions(input);
            input = null;
        }
    }

View on GitHub (pinned to 1b7edd19c4)