{"record":{"id":"9c9a0947098a5415","repo":"stanfordnlp/CoreNLP","slug":"error-incorrect-format-for-the-serialized-coref-g","errorCode":null,"errorMessage":"ERROR: Incorrect format for the serialized coref graph: ${line}","messagePattern":"ERROR: Incorrect format for the serialized coref graph: (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/CustomAnnotationSerializer.java","lineNumber":426,"sourceCode":"  }\n\n  @Override\n  public Pair<Annotation, InputStream> read(InputStream is) throws IOException {\n    if(compress && !(is instanceof GZIPInputStream)) is = new GZIPInputStream(is);\n    BufferedReader reader = new BufferedReader(new InputStreamReader(is));\n    Annotation doc = new Annotation(\"\");\n    String line;\n\n    // read the coref graph (new format)\n    Map<Integer, CorefChain> chains = loadCorefChains(reader);\n    if(chains != null) doc.set(CorefCoreAnnotations.CorefChainAnnotation.class, chains);\n\n    // read the coref graph (old format)\n    line = reader.readLine().trim();\n    if(line.length() > 0){\n      String [] bits = line.split(\" \");\n      if(bits.length % 4 != 0){\n        throw new RuntimeIOException(\"ERROR: Incorrect format for the serialized coref graph: \" + line);\n      }\n      List<Pair<IntTuple, IntTuple>> corefGraph = new ArrayList<>();\n      for(int i = 0; i < bits.length; i += 4){\n        IntTuple src = new IntTuple(2);\n        IntTuple dst = new IntTuple(2);\n        src.set(0, Integer.parseInt(bits[i]));\n        src.set(1, Integer.parseInt(bits[i + 1]));\n        dst.set(0, Integer.parseInt(bits[i + 2]));\n        dst.set(1, Integer.parseInt(bits[i + 3]));\n        corefGraph.add(new Pair<>(src, dst));\n      }\n      doc.set(CorefCoreAnnotations.CorefGraphAnnotation.class, corefGraph);\n    }\n\n    // read individual sentences\n    List<CoreMap> sentences = new ArrayList<>();\n    while((line = reader.readLine()) != null){\n      CoreMap sentence = new Annotation(\"\");","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CustomAnnotationSerializer.java#L408-L444","documentation":"CustomAnnotationSerializer.read parses the old-format coref graph line as space-separated fields in groups of 4 (source tuple + destination tuple). If the number of fields is not a multiple of 4, the line cannot represent complete (src,dst) pairs and a RuntimeIOException is thrown.","triggerScenarios":"Reading a serialized annotation whose coref graph line has a field count not divisible by 4 — a truncated/corrupted file or one written by an incompatible serializer version.","commonSituations":"Loading annotations serialized with a different CoreNLP version whose coref format changed; incomplete file transfers; hand-edited coref lines dropping a field.","solutions":["Regenerate the serialized annotation file with the same CoreNLP version used to read it","Check the coref line's field count is a multiple of 4 (sentIndex-copy pairs for src and dst)","Ensure the file transferred completely and was not truncated (compare checksums)","Use a consistent CustomAnnotationSerializer version for both write and read"],"exampleFix":"// before: truncated line with 6 fields (not multiple of 4)\n// 0-1 0-2 1-0 1-1 2-0 2-1\n// after: complete 4-field-group line\n// 0-1 0-2 1-0 1-1","handlingStrategy":"validation","validationCode":"String[] bits = corefLine.split(\" \");\nif (bits.length % 4 != 0) throw new IllegalArgumentException(\"Coref line not multiple of 4 fields: \" + corefLine);","typeGuard":"static boolean hasCompleteCorefGroups(String line) {\n  return line.trim().split(\" \").length % 4 == 0;\n}","tryCatchPattern":"try {\n  Pair<Annotation, InputStream> p = serializer.read(in);\n} catch (RuntimeIOException e) {\n  if (e.getMessage().startsWith(\"ERROR: Incorrect format for the serialized coref graph\")) {\n    // re-transfer or regenerate the file\n  } else throw e;\n}","preventionTips":["Verify file integrity with checksums after transfer","Use the same CoreNLP version to write and read serialized annotations","Avoid manual edits to coref graph lines","Test round-trip write/read when upgrading CoreNLP versions"],"tags":["java","serialization","corenlp","coref","malformed-input"],"backgroundTag":"invalid-argument-format","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"}