{"record":{"id":"a9bdb848649ccd24","repo":"stanfordnlp/CoreNLP","slug":"runtimeexception-wrapping-exception-dataset-read","errorCode":null,"errorMessage":"RuntimeException wrapping Exception (dataset read failure)","messagePattern":"RuntimeException wrapping Exception \\(dataset read failure\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/coref/statistical/MetadataWriter.java","lineNumber":40,"sourceCode":" * Writes various pieces of information about coreference documents to disk.\n * @author Kevin Clark\n */\npublic class MetadataWriter implements CorefDocumentProcessor {\n  private final Map<Integer, Map<Integer, String>> mentionTypes;\n  private final Map<Integer, List<List<Integer>>> goldClusters;\n  private final Counter<String> wordCounts;\n  private final Map<Integer, Map<Pair<Integer, Integer>, Boolean>> mentionPairs;\n  private final boolean countWords;\n\n  public MetadataWriter(boolean countWords) {\n    this.countWords = countWords;\n    mentionTypes = new HashMap<>();\n    goldClusters = new HashMap<>();\n    wordCounts = new ClassicCounter<>();\n    try {\n      mentionPairs = IOUtils.readObjectFromFile(StatisticalCorefTrainer.datasetFile);\n    } catch (Exception e) {\n      throw new RuntimeException(e);\n    }\n  }\n\n  @Override\n  public void process(int id, Document document) {\n    // Mention types\n    mentionTypes.put(id, document.predictedMentionsByID.entrySet().stream().collect(\n        Collectors.toMap(Map.Entry::getKey, e -> e.getValue().mentionType.toString())));\n\n    // Gold clusters\n    List<List<Integer>> clusters = new ArrayList<>();\n    for (CorefCluster c : document.goldCorefClusters.values()) {\n        List<Integer> cluster = new ArrayList<>();\n        for (Mention m : c.getCorefMentions()) {\n            cluster.add(m.mentionID);\n        }\n        clusters.add(cluster);\n    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/statistical/MetadataWriter.java#L22-L58","documentation":"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.","triggerScenarios":"Constructing MetadataWriter when datasetFile is missing/unreadable, or the object stream is corrupt or incompatible (wrong CoreNLP version / class changes).","commonSituations":"Running the metadata writer before the dataset was built; CoreNLP version mismatch causing InvalidClassException during deserialization; file moved or path misconfigured.","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"],"exampleFix":"// before\n} catch (Exception e) {\n  throw new RuntimeException(e);\n}\n// after\n} catch (Exception e) {\n  throw new RuntimeException(\"Error reading mention-pair dataset from \"\n      + StatisticalCorefTrainer.datasetFile, e);\n}","handlingStrategy":"try-catch","validationCode":"// ensure dataset exists before constructing MetadataWriter\nif (StatisticalCorefTrainer.datasetFile == null)\n  throw new IllegalStateException(\"datasetFile not set — run dataset build stage first\");\njava.io.File f = new java.io.File(datasetPath);\nif (!f.isFile() || !f.canRead()) throw new IllegalStateException(\"Dataset missing: \" + datasetPath);","typeGuard":null,"tryCatchPattern":"try {\n  MetadataWriter mw = new MetadataWriter(props, dictionaries);\n} catch (RuntimeException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof java.io.FileNotFoundException)\n    throw new IllegalStateException(\"Dataset not built yet\", e);\n  if (cause instanceof java.io.InvalidClassException)\n    throw new IllegalStateException(\"CoreNLP version mismatch for serialized dataset\", e);\n  throw e;\n}","preventionTips":["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"],"tags":["java","corenlp","deserialization","initialization"],"backgroundTag":"file-read-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}