stanfordnlp/CoreNLP · error · RuntimeException

Unexpected format " + outputStyle

Error message

Unexpected format " + outputStyle

What it means

tagAndOutputSentence switches on the OutputStyle enum and throws a plain RuntimeException 'Unexpected format <outputStyle>' in the default branch, meaning the configured output style is not one of the implemented formats (xml, tsv, text, etc.). This usually indicates an unrecognized outputFormat config value mapped to an OutputStyle the writer cannot handle, or a new enum constant without a corresponding case.

Solutions

  1. Set outputFormat to a supported value: 'text', 'tsv', or 'xml'.
  2. Check OutputStyle.fromShortName accepted names for your CoreNLP version and correct the config.
  3. Upgrade/align CoreNLP version so config and enum handling match.
  4. If adding a new OutputStyle, implement its case in the switch before using it.

Example fix

// before
props.setProperty("outputFormat", "JSON"); // unsupported -> RuntimeException
// after
props.setProperty("outputFormat", "tsv"); // or "xml" / "text"
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<String> supported = java.util.Set.of("text", "tsv", "xml");
if (!supported.contains(config.getOutputFormat())) throw new IllegalArgumentException("Unsupported outputFormat: " + config.getOutputFormat());

Try / catch

try {
  tagger.tagAndOutputSentence(sent, outputStyle, ...);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("Unexpected format")) {
    throw new IllegalArgumentException("Use text/tsv/xml outputFormat", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Config outputFormat resolving (via OutputStyle.fromShortName) to an OutputStyle with no case in tagAndOutputSentence's switch; programmatically passing an exotic OutputStyle constant.

Common situations: Typo or unsupported value in the outputFormat property; library version where a config value maps to an OutputStyle not handled by this method; copying an OutputStyle constant between code versions.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/a59aabe0f453ea93. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/tagger/maxent/MaxentTagger.java:1502

  public void tagFromXML(InputStream input, Writer writer, String... xmlTags) {
    OutputStyle outputStyle = OutputStyle.fromShortName(config.getOutputFormat());

    TransformXML<String> txml = new TransformXML<>();
    switch(outputStyle) {
    case XML:
    case INLINE_XML:
      txml.transformXML(xmlTags, new TaggerWrapper(this),
                        input, writer,
                        new TransformXML.NoEscapingSAXInterface<>());
      break;
    case SLASH_TAGS:
    case TSV:
      txml.transformXML(xmlTags, new TaggerWrapper(this),
                        input, writer,
                        new TransformXML.SAXInterface<>());
      break;
    default:
      throw new RuntimeException("Unexpected format " + outputStyle);
    }
  }

  public void tagFromXML(Reader input, Writer writer, String... xmlTags) {
    OutputStyle outputStyle =
      OutputStyle.fromShortName(config.getOutputFormat());

    TransformXML<String> txml = new TransformXML<>();
    switch(outputStyle) {
    case XML:
    case INLINE_XML:
      txml.transformXML(xmlTags, new TaggerWrapper(this),
                        input, writer,
                        new TransformXML.NoEscapingSAXInterface<>());
      break;
    case SLASH_TAGS:
    case TSV:
      txml.transformXML(xmlTags, new TaggerWrapper(this),

View on GitHub (pinned to 1b7edd19c4)