stanfordnlp/CoreNLP · error · IOException
Unsupported file format: " + filename
Error message
Unsupported file format: " + filename
What it means
AnnotationIterator's constructor dispatches on filename extension (.jsonl, .proto, etc.) to choose the input stream and serializer; an unrecognized extension throws IOException since it cannot decide how to deserialize annotations.
Solutions
- Rename the file to have a supported extension: .jsonl for JSON Lines or .proto for protobuf serialization
- Convert your corpus to JSON Lines or protobuf-serialized annotations first
- Check for trailing characters in the path (quotes, whitespace, .gz suffix) that break endsWith
- If reading serialized annotations, serialize them with ProtobufAnnotationSerializer or the JSON outputter to match the extension
Example fix
// before
AnnotationIterator it = new AnnotationIterator("docs.json");
// after
AnnotationIterator it = new AnnotationIterator("docs.jsonl"); Defensive patterns
Strategy: validation
Validate before calling
String lower = filename.toLowerCase();
if (!lower.endsWith(".jsonl") && !lower.endsWith(".proto")) {
throw new IllegalArgumentException("Rename to .jsonl or .proto: " + filename);
}
AnnotationIterator it = new AnnotationIterator(filename); Type guard
boolean isSupportedAnnotationFile(String f) {
return f != null && (f.endsWith(".jsonl") || f.endsWith(".proto"));
} Try / catch
try {
it = new AnnotationIterator(filename);
} catch (IOException e) {
if (e.getMessage().startsWith("Unsupported file format")) {
System.err.println("Convert file to .jsonl or .proto first");
} else throw e;
} Prevention
- Rename files to .jsonl or .proto before feeding to CoreNLP
- Convert .json (single object) outputs to JSON Lines
- Watch for trailing whitespace/quotes in paths
- Standardize corpus serialization format
When it happens
Trigger: Constructing AnnotationIterator (or AnnotationOutputter-driven pipelines reading a corpus file) with a path not ending in a supported extension such as .jsonl or .proto.
Common situations: Passing a .json file where .jsonl is expected, an extensionless file, .txt dumps, or a compressed variant (.gz) the constructor doesn't recognize.
Related errors
- Error reading from " + this.filename
- Error loading classifier from
- edu.stanford.nlp.io.RuntimeIOException
- Unexpected number of field , expected >= for line (,):
- Error creating data exporter
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2101c9fac5f23399.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/AnnotationIterator.java:44
JSONAnnotationReader jsonReader = new JSONAnnotationReader();
String format;
int docCnt = 0;
int limit = 0;
public AnnotationIterator(String filename) throws IOException {
this.filename = filename;
if (filename.endsWith(".json")) {
this.br = IOUtils.readerFromString(filename);
this.format = "json";
} else if (filename.endsWith(".jsonl")) {
this.br = IOUtils.readerFromString(filename);
this.format = "jsonl";
} else if (filename.endsWith(".proto")) {
this.input = IOUtils.getFileInputStream(filename);
this.serializer = new ProtobufAnnotationSerializer();
this.format = "proto";
} else {
throw new IOException("Unsupported file format: " + filename);
}
nextDoc = readNextDocument();
}
public AnnotationIterator(String filename, int limit) throws IOException {
this(filename);
this.limit = limit;
}
@Override
public boolean hasNext() {
return nextDoc != null;
}
@Override
public Annotation next() {
if (nextDoc == null) {
throw new NoSuchElementException("DocumentIterator exhausted.");View on GitHub (pinned to 1b7edd19c4)