{"record":{"id":"a3aa77213c64a942","repo":"stanfordnlp/CoreNLP","slug":"format-error-unexpected-featurefactory-line","errorCode":null,"errorMessage":"format error unexpected featureFactory line: ","messagePattern":"format error unexpected featureFactory line: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":2234,"sourceCode":"      count = 0;\n      while (count < embeddingSize) {\n        line = br.readLine().trim();\n        toks = line.split(\"\\\\t\");\n        String word = toks[0];\n        double[] arr = ArrayUtils.toDoubleArray(toks[1].split(\" \"));\n        embeddings.put(word, arr);\n        count++;\n      }\n    }\n\n    // <featureFactory>\n    // edu.stanford.nlp.wordseg.Gale2007ChineseSegmenterFeatureFactory\n    // </featureFactory>\n    line = br.readLine();\n\n    String[] featureFactoryName = line.split(\" \");\n    if (featureFactoryName.length < 2 || !featureFactoryName[0].equals(\"<featureFactory>\") || !featureFactoryName[featureFactoryName.length - 1].equals(\"</featureFactory>\")) {\n      throw new RuntimeException(\"format error unexpected featureFactory line: \" + line);\n    }\n    featureFactories = Generics.newArrayList();\n    for (int ff = 1; ff < featureFactoryName.length - 1; ++ff) {\n      FeatureFactory<IN> featureFactory = (FeatureFactory<IN>) Class.forName(featureFactoryName[1]).newInstance();\n      featureFactory.init(flags);\n      featureFactories.add(featureFactory);\n    }\n\n    reinit();\n\n    // <windowSize> 2 </windowSize>\n    line = br.readLine();\n\n    String[] windowSizeName = line.split(\" \");\n    if (!windowSizeName[0].equals(\"<windowSize>\") || !windowSizeName[2].equals(\"</windowSize>\")) {\n      throw new RuntimeException(\"format error\");\n    }\n    windowSize = Integer.parseInt(windowSizeName[1]);","sourceCodeStart":2216,"sourceCodeEnd":2252,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L2216-L2252","documentation":"Thrown when the featureFactory line of the text-serialized model does not match the expected '<featureFactory> name </featureFactory>' layout: it must contain at least the open/close markers and the class name between them. The message appends the offending line.","triggerScenarios":"CRFClassifier.getClassifier on a model whose featureFactory line lacks '<featureFactory>'/'</featureFactory>' markers, has fewer than 2 space-separated tokens, or was wrapped/reformatted onto multiple lines.","commonSituations":"Text editors or formatters reflowed the long featureFactory line; custom models whose writer used a different marker format; edits or corruption in the flags/featureFactory region.","solutions":["Ensure the line is exactly '<featureFactory> edu.stanford.nlp...FeatureFactory </featureFactory>' on one line","Reformat the line back to a single line if an editor wrapped it","Regenerate the model with CRFClassifier.writeModel from the same CoreNLP version","Confirm the FeatureFactory class name is fully qualified (the loader also calls Class.forName on it)"],"exampleFix":"// before: line wrapped/reformatted in the model file\n// <featureFactory>\n// edu.stanford.nlp.wordseg.ChineseSegmenterFeatureFactory\n// </featureFactory>\n// after: single line with markers\n// <featureFactory> edu.stanford.nlp.wordseg.ChineseSegmenterFeatureFactory </featureFactory>","handlingStrategy":"validation","validationCode":"// Validate the featureFactory line format before loading\nstatic boolean featureFactoryLineValid(String line) {\n  if (line == null) return false;\n  String[] toks = line.split(\" \");\n  return toks.length >= 2 && toks[0].equals(\"<featureFactory>\") && toks[toks.length - 1].equals(\"</featureFactory>\");\n}","typeGuard":"static boolean isFeatureFactoryLine(String line) {\n  String[] toks = line == null ? new String[0] : line.split(\" \");\n  return toks.length >= 2 && \"<featureFactory>\".equals(toks[0]) && \"</featureFactory>\".equals(toks[toks.length - 1]);\n}","tryCatchPattern":"try {\n  CRFClassifier<CoreLabel> model = CRFClassifier.getClassifier(modelPath);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"format error unexpected featureFactory line:\")) {\n    throw new IllegalStateException(\"featureFactory line malformed (check it is one unwrapped line with both markers).\", e);\n  }\n  throw e;\n}","preventionTips":["Keep the featureFactory line on a single line — disable editor auto-wrap for model files","Use fully-qualified FeatureFactory class names so Class.forName resolves","Regenerate models rather than editing the featureFactory section by hand","Avoid reformatting/whitespace normalization on serialized models"],"tags":["java","stanford-corenlp","model-loading","feature-factory","file-format"],"backgroundTag":"schema-validation-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"}