stanfordnlp/CoreNLP · error · RuntimeException
invalid line
Error message
invalid line '%s'
What it means
findAnnotation scans gigaword document lines looking for the '</DOC>' terminator. A line that merely CONTAINS '</DOC>' but is not exactly that string means the document markup is malformed (trailing content on the closing tag), so it throws a RuntimeException with the offending line rather than silently mis-parsing the document.
Solutions
- Normalize the input file: strip trailing whitespace/CR characters after '</DOC>' and re-save.
- Pre-process each line with line.trim() comparison logic or fix the file so the closing tag stands alone.
- Re-download or re-extract the gigaword archive to rule out extraction corruption.
Example fix
// before
if (line.contains("</DOC>")) {
throw new RuntimeException(String.format("invalid line '%s'", line));
}
// after
if (line.trim().equals("</DOC>")) {
break;
} Defensive patterns
Strategy: validation
Validate before calling
if (line.contains("</DOC>") && !line.trim().equals("</DOC>")) {
logger.warning("Malformed </DOC> line: " + line);
line = line.trim(); // or sanitize the corpus beforehand
} Try / catch
try {
return it.next();
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("invalid line")) {
logger.warning("Skipping malformed document boundary");
}
throw e;
} Prevention
- Sanitize gigaword files (strip CRLF and trailing whitespace) before parsing
- Re-verify checksums of downloaded corpora
- Add a corpus pre-validation pass that flags malformed DOC tags
When it happens
Trigger: Reading a gigaword file whose '</DOC>' closing tag has trailing whitespace, characters, or CRLF remnants making line.equals("</DOC>") false while line.contains("</DOC>") is true.
Common situations: Corrupted or re-encoded gigaword archives; files edited by tools that appended spaces or converted line endings; concatenated documents leaving stray markup after the closing tag.
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
- Unparsable sentence:
- error:\n \ninput:\n
- Error (line ): 10 fields expected but are present
- Bad data format:
- Cannot find matching labelled span for
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2019d84997b9d976.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/time/ParsedGigawordReader.java:94
private Annotation findAnnotation() {
if (this.reader == null) {
return null;
}
try {
String line;
StringBuilder doc = new StringBuilder();
while ((line = this.reader.readLine()) != null) {
doc.append(line);
doc.append('\n');
// if(line.contains("<DOC id")){
// log.info(line);
// }
if (line.equals("</DOC>")) {
break;
}
if (line.contains("</DOC>")) {
throw new RuntimeException(String.format("invalid line '%s'", line));
}
}
if (line == null) {
this.reader.close();
this.reader = findReader();
}
String xml = doc.toString().replaceAll("&", "&");
if(xml == null || xml.equals("")) {
return findAnnotation();
}
xml = xml.replaceAll("num=([0-9]+) (.*)", "num=\"$1\" $2");
xml = xml.replaceAll("sid=(.*)>", "sid=\"$1\">");
xml = xml.replaceAll("</SENT>\n</DOC>", "</SENT>\n</TEXT>\n</DOC>");
xml = new String(xml.getBytes(), "UTF8");
//log.info("This is what goes in:\n" + xml);
return toAnnotation(xml);
} catch (IOException e) {View on GitHub (pinned to 1b7edd19c4)