stanfordnlp/CoreNLP · error · RuntimeException
Error annotating
Error message
Error annotating ${file.getAbsoluteFile()} What it means
In the multi-file/batch annotate path (annotateFiles-style), when annotating an input file throws and the run is configured to stop on error (clearPool true), the worker wraps the cause in RuntimeException 'Error annotating <file>'. It identifies which file failed while preserving the underlying exception.
Solutions
- Inspect the cause (ex) attached to the RuntimeException - fix the underlying annotation failure for that file.
- Validate/pre-filter input files (non-empty, valid encoding) before batch annotation.
- Configure the run to continue on error instead of clearing the pool, and log/skip the bad file.
- Increase memory (-Xmx) or split very large files if the cause is resource exhaustion.
Example fix
// before
// batch annotate crashes whole run on one bad file
pipeline.annotate(files);
// after
for (CoreDocument doc : docs) {
try { pipeline.annotate(doc); }
catch (Exception e) { log.warn("Skipping bad document", e); }
} Defensive patterns
Strategy: try-catch
Validate before calling
for (File f : inputFiles) {
if (!f.isFile() || f.length() == 0) log.warn("Skipping empty/invalid file: " + f);
} Try / catch
try {
pipeline.annotate(annotation);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Error annotating ")) {
log.error("Failed on {} cause {}", e.getMessage(), e.getCause());
} else throw e;
} Prevention
- Always inspect getCause() to find the real annotation failure.
- Pre-validate corpus files for encoding and non-empty content.
- Size the thread pool and heap appropriately for the largest documents.
- Process files one-per-try/catch so a single failure does not kill the batch.
When it happens
Trigger: Running pipeline.annotate over a collection/directory of files with -replaceInput/-outputExtension style batch processing; one document makes an annotator throw (e.g. tokenizer or parse failure, malformed encoding, empty/garbage input) and requireException/clearPool is set.
Common situations: Batch-annotating a mixed corpus where one file has corrupt encoding or an empty body; out-of-memory or thread-pool issues on huge files; model files missing so an annotator throws on first document.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- addFeature was called with a features object that is…
- adjustFinalToken: Unexpected final char: |
- after W derivative, index() != x.length()
- An error occurred while testing the tagger.
- Annotation field cannot be null
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/077c880c3ce48676.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/StanfordCoreNLP.java:1402
synchronized (totalErrorAnnotating) {
totalErrorAnnotating.incValue(1);
// check we've processed or errored on every file, handle tasks to run after last document
if ((totalProcessed.intValue() + totalErrorAnnotating.intValue()) == files.size()) {
// clear pool if necessary
if (clearPool)
GLOBAL_ANNOTATOR_CACHE.clear();
// print out timing info
if (TIME && pipeline.isPresent() && tim.isPresent())
logTimingInfo(pipeline.get(), tim.get());
}
}
} else {
// if stopping due to error, make sure to clear the pool
if (clearPool) {
GLOBAL_ANNOTATOR_CACHE.clear();
}
throw new RuntimeException("Error annotating " + file.getAbsoluteFile(), ex);
}
});
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
}
public void processFiles(final Collection<File> files, int numThreads, boolean clearPool, Optional<Timing> tim) throws IOException {
processFiles(null, files, numThreads, clearPool, tim);
}
public void processFiles(final Collection<File> files, boolean clearPool, Optional<Timing> tim) throws IOException {
processFiles(files, 1, clearPool, tim);
}
View on GitHub (pinned to 1b7edd19c4)