stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown outputFormat:

Error message

Unknown outputFormat: 

What it means

Sighan2005DocumentReaderAndWriter.printAnswers switches on the configured outputFormat when writing segmentation answers. Hitting the default branch means the OutputFormat enum value isn't one of the handled cases, so IllegalArgumentException('Unknown outputFormat: ...') is thrown.

Solutions

  1. Set outputFormat to a supported value (e.g. the plain-text or CoNLL-U handled cases)
  2. Add a case for the new OutputFormat in printAnswers before using it
  3. Check which OutputFormat values printAnswers supports and align configuration

Example fix

// before
flags.outputFormat = OutputFormat.MY_NEW_FORMAT;
// after
flags.outputFormat = OutputFormat.CONLLU; // or add a case in printAnswers
Defensive patterns

Strategy: validation

Validate before calling

// only run main with handled formats
if (flags.outputFormat != OutputFormat.PLAIN_TEXT && flags.outputFormat != OutputFormat.CONLLU) {
  flags.outputFormat = OutputFormat.CONLLU;
}

Try / catch

try {
  readerAndWriter.printAnswers(doc, pw);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Unknown outputFormat")) {
    flags.outputFormat = OutputFormat.CONLLU;
    readerAndWriter.printAnswers(doc, pw);
  } else throw e;
}

Prevention

When it happens

Trigger: Running the Sighan2005 test/writer main with an outputFormat set to an enum value not handled by the switch (e.g. a newly added OutputFormat constant not covered here).

Common situations: Adding a new OutputFormat to the enum without updating printAnswers; misconfigured properties mapping to an unhandled format; running main directly with a format the writer never supported.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/wordseg/Sighan2005DocumentReaderAndWriter.java:375

      }
      pw.print("\t_\t_");
      pw.println();
    }

    pw.println();
  }

  @Override
  public void printAnswers(List<CoreLabel> doc, PrintWriter pw) {
    switch (outputFormat) {
    case PLAINTEXT:
      printPlainTextAnswer(doc, pw);
      break;
    case CONLLU:
      printConlluAnswer(doc, pw);
      break;
    default:
      throw new IllegalArgumentException("Unknown outputFormat: " + outputFormat);
    }
  }


  private static String intern(String s) {
    return s.trim().intern();
  }

  @Override
  public void printLattice(DFSA<String, Integer> tagLattice, List<CoreLabel> doc, PrintWriter out) {
    CoreLabel[] docArray = doc.toArray(new CoreLabel[doc.size()]);
    // Create answer lattice:
    MutableInteger nodeId = new MutableInteger(0);
    DFSA<String, Integer> answerLattice = new DFSA<>(null);
    DFSAState<String, Integer> aInitState = new DFSAState<>(nodeId.intValue(), answerLattice);
    answerLattice.setInitialState(aInitState);
    Map<DFSAState<String, Integer>,DFSAState<String, Integer>> stateLinks = Generics.newHashMap();
    // Convert binary lattice into word lattice:

View on GitHub (pinned to 1b7edd19c4)