stanfordnlp/CoreNLP · error · RuntimeException
RuntimeException wrapping Exception (dataset read failure)
Error message
RuntimeException wrapping Exception (dataset read failure)
What it means
MetadataWriter's constructor reads the serialized mention-pair dataset (StatisticalCorefTrainer.datasetFile) via IOUtils.readObjectFromFile and wraps any Exception in a plain RuntimeException(e) — no message, only the cause. This is the metadata-writing stage of statistical coref training failing to load its input dataset.
Solutions
- Run the dataset-creation stage first so datasetFile exists
- Verify StatisticalCorefTrainer.datasetFile points at the correct file for this run
- Use a matching CoreNLP version for deserialization to avoid class-incompatibility errors
- Inspect the wrapped cause (e.getCause()) — FileNotFoundException vs InvalidClassException vs IOException — and fix accordingly
Example fix
// before
} catch (Exception e) {
throw new RuntimeException(e);
}
// after
} catch (Exception e) {
throw new RuntimeException("Error reading mention-pair dataset from "
+ StatisticalCorefTrainer.datasetFile, e);
} Defensive patterns
Strategy: try-catch
Validate before calling
// ensure dataset exists before constructing MetadataWriter
if (StatisticalCorefTrainer.datasetFile == null)
throw new IllegalStateException("datasetFile not set — run dataset build stage first");
java.io.File f = new java.io.File(datasetPath);
if (!f.isFile() || !f.canRead()) throw new IllegalStateException("Dataset missing: " + datasetPath); Try / catch
try {
MetadataWriter mw = new MetadataWriter(props, dictionaries);
} catch (RuntimeException e) {
Throwable cause = e.getCause();
if (cause instanceof java.io.FileNotFoundException)
throw new IllegalStateException("Dataset not built yet", e);
if (cause instanceof java.io.InvalidClassException)
throw new IllegalStateException("CoreNLP version mismatch for serialized dataset", e);
throw e;
} Prevention
- Build the mention-pair dataset before running MetadataWriter
- Serialize and deserialize with the same CoreNLP version
- Verify dataset path configuration at startup
- Unwrap e.getCause() to identify missing-file vs class-incompatibility issues
When it happens
Trigger: Constructing MetadataWriter when datasetFile is missing/unreadable, or the object stream is corrupt or incompatible (wrong CoreNLP version / class changes).
Common situations: Running the metadata writer before the dataset was built; CoreNLP version mismatch causing InvalidClassException during deserialization; file moved or path misconfigured.
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
- Error initializing FeatureExtractorRunner
- Couldn't load
- Couldn't load classifier!
- ERROR: Serialized data does not contain an Annotation!
- Error loading classifier from
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/a9bdb848649ccd24.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/coref/statistical/MetadataWriter.java:40
* Writes various pieces of information about coreference documents to disk.
* @author Kevin Clark
*/
public class MetadataWriter implements CorefDocumentProcessor {
private final Map<Integer, Map<Integer, String>> mentionTypes;
private final Map<Integer, List<List<Integer>>> goldClusters;
private final Counter<String> wordCounts;
private final Map<Integer, Map<Pair<Integer, Integer>, Boolean>> mentionPairs;
private final boolean countWords;
public MetadataWriter(boolean countWords) {
this.countWords = countWords;
mentionTypes = new HashMap<>();
goldClusters = new HashMap<>();
wordCounts = new ClassicCounter<>();
try {
mentionPairs = IOUtils.readObjectFromFile(StatisticalCorefTrainer.datasetFile);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void process(int id, Document document) {
// Mention types
mentionTypes.put(id, document.predictedMentionsByID.entrySet().stream().collect(
Collectors.toMap(Map.Entry::getKey, e -> e.getValue().mentionType.toString())));
// Gold clusters
List<List<Integer>> clusters = new ArrayList<>();
for (CorefCluster c : document.goldCorefClusters.values()) {
List<Integer> cluster = new ArrayList<>();
for (Mention m : c.getCorefMentions()) {
cluster.add(m.mentionID);
}
clusters.add(cluster);
}View on GitHub (pinned to 1b7edd19c4)