{"record":{"id":"08659063ceadb653","repo":"stanfordnlp/CoreNLP","slug":"format-error","errorCode":null,"errorMessage":"format error","messagePattern":"format error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":2105,"sourceCode":"  protected static List<List<CRFDatum<Collection<String>, String>>> loadProcessedData(String filename) {\n    List<List<CRFDatum<Collection<String>, String>>> result;\n    try {\n      result = IOUtils.readObjectFromURLOrClasspathOrFileSystem(filename);\n    } catch (Exception e) {\n      log.warn(e);\n      result = Collections.emptyList();\n    }\n    log.info(\"Loading processed data from serialized file ... done. Got \" + result.size() + \" datums.\");\n    return result;\n  }\n\n  protected void loadTextClassifier(BufferedReader br) throws Exception {\n    String line = br.readLine();\n    // first line should be this format:\n    // labelIndices.size()=\\t%d\n    String[] toks = line.split(\"\\\\t\");\n    if (!toks[0].equals(\"labelIndices.length=\")) {\n      throw new RuntimeException(\"format error\");\n    }\n    int size = Integer.parseInt(toks[1]);\n    labelIndices = new ArrayList<>(size);\n    for (int labelIndicesIdx = 0; labelIndicesIdx < size; labelIndicesIdx++) {\n      line = br.readLine();\n      // first line should be this format:\n      // labelIndices.length=\\t%d\n      // labelIndices[0].size()=\\t%d\n      toks = line.split(\"\\\\t\");\n      if (!(toks[0].startsWith(\"labelIndices[\") && toks[0].endsWith(\"].size()=\"))) {\n        throw new RuntimeException(\"format error\");\n      }\n      int labelIndexSize = Integer.parseInt(toks[1]);\n      labelIndices.add(new HashIndex<>());\n      int count = 0;\n      while (count < labelIndexSize) {\n        line = br.readLine();\n        toks = line.split(\"\\\\t\");","sourceCodeStart":2087,"sourceCodeEnd":2123,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L2087-L2123","documentation":"loadTextClassifier parses a text-serialized CRF line by line and requires a strict header line \"labelIndices.length=\\t<size>\". If the first tab-separated token doesn't equal \"labelIndices.length=\", it throws this RuntimeException, meaning the stream is not in the expected text format (wrong loader, wrong file, or version mismatch).","triggerScenarios":"Calling loadTextClassifier on a binary serialized classifier, an empty/truncated/corrupt file, a manually edited file, or a model saved by a different Stanford NLP version with a changed text format.","commonSituations":"Mixing serializeTo (binary) output with the text loader; passing the wrong file path; loading models across incompatible library versions.","solutions":["Use the matching loader: binary files go through the binary load path (getClassifier/serializeTo); loadTextClassifier only reads files written by serializeTextClassifier.","Verify the file's first line is exactly \"labelIndices.length=\\t<N>\" (key, TAB, integer).","Re-serialize the classifier with the same library version that reads it.","Confirm the path points at the intended file and that it isn't truncated."],"exampleFix":"// before\n// file saved with serializeTo (binary) but read as text -> \"format error\"\nclassifier.loadTextClassifier(new BufferedReader(new FileReader(\"/models/ner.ser.gz\")));\n// after\n// save text: classifier.serializeTextClassifier(\"/models/ner.txt\");\nclassifier.loadTextClassifier(new BufferedReader(new FileReader(\"/models/ner.txt\")));","handlingStrategy":"validation","validationCode":"try (BufferedReader br = new BufferedReader(new FileReader(modelFile))) {\n  String first = br.readLine();\n  if (first == null || !first.split(\"\\t\")[0].equals(\"labelIndices.length=\")) {\n    throw new IllegalArgumentException(modelFile + \" is not a text-serialized CRF; use the binary loader\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  classifier.loadTextClassifier(br);\n} catch (Exception e) {\n  if (String.valueOf(e.getMessage()).contains(\"format error\")) {\n    // wrong loader or corrupt file: fall back to the binary loader\n    classifier = CRFClassifier.getClassifier(modelFile);\n  } else throw e;\n}","preventionTips":["Match loader to writer: loadTextClassifier only for serializeTextClassifier output.","Peek at the first line (labelIndices.length=\\tN) before parsing.","Keep trainer and loader on the same Stanford NLP version."],"tags":["java","serialization","crf","parsing"],"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"}