{"record":{"id":"6f1f90469a9a1d6d","repo":"stanfordnlp/CoreNLP","slug":"could-not-parse-conll-file","errorCode":null,"errorMessage":"Could not parse CoNLL file","messagePattern":"Could not parse CoNLL file","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/KBPRelationExtractor.java","lineNumber":383,"sourceCode":"    while ( (line = reader.readLine()) != null ) {\n      String[] fields = line.split(\"\\t\");\n      if (relation == null) {\n        // Case: read the relation\n        assert fields.length == 1;\n        relation = fields[0];\n      } else if (fields.length == 9) {\n        // Case: read a token\n        tokens.add(fields[0]);\n        if (\"SUBJECT\".equals(fields[1])) {\n          subject = new Span(Math.min(subject.start(), i), Math.max(subject.end(), i + 1));\n          subjectNER = valueOf(fields[2].toUpperCase(Locale.ROOT));\n        } else if (\"OBJECT\".equals(fields[3])) {\n          object = new Span(Math.min(object.start(), i), Math.max(object.end(), i + 1));\n          objectNER = valueOf(fields[4].toUpperCase(Locale.ROOT));\n        } else if (\"-\".equals(fields[1]) && \"-\".equals(fields[3])) {\n          // do nothing\n        } else {\n          throw new IllegalStateException(\"Could not parse CoNLL file\");\n        }\n        i += 1;\n      } else if (StringUtils.isNullOrEmpty(line.trim())) {\n        // Case: commit a sentence\n        examples.add(Pair.makePair(new KBPInput(\n            subject,\n            object,\n            subjectNER,\n            objectNER,\n            new Sentence(tokens)\n        ), relation));\n\n        // (clear the variables)\n        i = 0;\n        relation = null;\n        tokens = new ArrayList<>();\n        subject = new Span(Integer.MAX_VALUE, Integer.MIN_VALUE);\n        object = new Span(Integer.MAX_VALUE, Integer.MIN_VALUE);","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/KBPRelationExtractor.java#L365-L401","documentation":"While reading CoNLL-format data lines, readDataset dispatches on the field at index 3 (SUBJECT/OBJECT/'-'). If fields[1] and fields[3] don't match any known role pattern, the line doesn't conform to the expected KBP CoNLL schema and it throws an IllegalStateException.","triggerScenarios":"A data line whose 4th column (role) is neither SUBJECT, OBJECT, nor the '-' pair ('-' in fields[1] and fields[3]) — e.g. malformed rows, wrong delimiter, or a truncated file with shifted columns.","commonSituations":"Hand-edited or merged CoNLL files; tab vs space delimiters altering column positions; rows from a different CoNLL task schema.","solutions":["Validate each line has the expected tab-separated columns before feeding the file","Fix rows whose role column is not SUBJECT/OBJECT/'-' (fields[3])","Ensure the file uses tabs, not spaces, as delimiters","Cross-check your file against the official KBP example input format"],"exampleFix":"// before (space-delimited, fields shift)\nJohn_SUBJ ... OBJECT ... // line read with split(\"\\t\") yields wrong roles\n// after\n// ensure tab separation: \"tok\\tO\\tO\\tSUBJECT\\tPERSON\"\nreadDataset(\"fixed.conll\");","handlingStrategy":"validation","validationCode":"int lineNo = 0;\nfor (String line : Files.readAllLines(Paths.get(file))) {\n  lineNo++;\n  if (line.isEmpty() || line.startsWith(\"#\")) continue;\n  String[] f = line.split(\"\\t\", -1);\n  if (f.length < 5) throw new IllegalStateException(\"line \" + lineNo + \" has \" + f.length + \" columns\");\n  boolean ok = \"SUBJECT\".equals(f[3]) || \"OBJECT\".equals(f[3])\n      || (\"-\".equals(f[1]) && \"-\".equals(f[3]));\n  if (!ok) throw new IllegalStateException(\"line \" + lineNo + \" bad role: \" + f[3]);\n}","typeGuard":null,"tryCatchPattern":"try {\n  readDataset(path);\n} catch (IllegalStateException e) {\n  log.error(\"CoNLL parse failed — check tabs/columns: \" + e.getMessage());\n  throw e;\n}","preventionTips":["Enforce tab delimiters in any data-prep scripts","Validate the role column (index 3) contains only SUBJECT/OBJECT/'-'","Diff generated files against the official sample"],"tags":["java","corenlp","kbp","conll-parse"],"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"}