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

  1. Rename the file to have a supported extension: .jsonl for JSON Lines or .proto for protobuf serialization
  2. Convert your corpus to JSON Lines or protobuf-serialized annotations first
  3. Check for trailing characters in the path (quotes, whitespace, .gz suffix) that break endsWith
  4. 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

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


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)