stanfordnlp/CoreNLP · error · IllegalStateException
Could not parse CoNLL file
Error message
Could not parse CoNLL file
What it means
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.
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
Example fix
// before (space-delimited, fields shift)
John_SUBJ ... OBJECT ... // line read with split("\t") yields wrong roles
// after
// ensure tab separation: "tok\tO\tO\tSUBJECT\tPERSON"
readDataset("fixed.conll"); Defensive patterns
Strategy: validation
Validate before calling
int lineNo = 0;
for (String line : Files.readAllLines(Paths.get(file))) {
lineNo++;
if (line.isEmpty() || line.startsWith("#")) continue;
String[] f = line.split("\t", -1);
if (f.length < 5) throw new IllegalStateException("line " + lineNo + " has " + f.length + " columns");
boolean ok = "SUBJECT".equals(f[3]) || "OBJECT".equals(f[3])
|| ("-".equals(f[1]) && "-".equals(f[3]));
if (!ok) throw new IllegalStateException("line " + lineNo + " bad role: " + f[3]);
} Try / catch
try {
readDataset(path);
} catch (IllegalStateException e) {
log.error("CoNLL parse failed — check tabs/columns: " + e.getMessage());
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Hand-edited or merged CoNLL files; tab vs space delimiters altering column positions; rows from a different CoNLL task schema.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- cannot be cast into a…
- First line of input file should be header definition
- Gabor sucks at logic and he should feel bad about it
- cannot be cast into a
- Shouldn't happen:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6f1f90469a9a1d6d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/KBPRelationExtractor.java:383
while ( (line = reader.readLine()) != null ) {
String[] fields = line.split("\t");
if (relation == null) {
// Case: read the relation
assert fields.length == 1;
relation = fields[0];
} else if (fields.length == 9) {
// Case: read a token
tokens.add(fields[0]);
if ("SUBJECT".equals(fields[1])) {
subject = new Span(Math.min(subject.start(), i), Math.max(subject.end(), i + 1));
subjectNER = valueOf(fields[2].toUpperCase(Locale.ROOT));
} else if ("OBJECT".equals(fields[3])) {
object = new Span(Math.min(object.start(), i), Math.max(object.end(), i + 1));
objectNER = valueOf(fields[4].toUpperCase(Locale.ROOT));
} else if ("-".equals(fields[1]) && "-".equals(fields[3])) {
// do nothing
} else {
throw new IllegalStateException("Could not parse CoNLL file");
}
i += 1;
} else if (StringUtils.isNullOrEmpty(line.trim())) {
// Case: commit a sentence
examples.add(Pair.makePair(new KBPInput(
subject,
object,
subjectNER,
objectNER,
new Sentence(tokens)
), relation));
// (clear the variables)
i = 0;
relation = null;
tokens = new ArrayList<>();
subject = new Span(Integer.MAX_VALUE, Integer.MIN_VALUE);
object = new Span(Integer.MAX_VALUE, Integer.MIN_VALUE);View on GitHub (pinned to 1b7edd19c4)