stanfordnlp/CoreNLP · error · IllegalArgumentException

is not an OutputStyle

Error message

 is not an OutputStyle

What it means

PlainTextDocumentReaderAndWriter.OutputStyle.fromShortName maps a user-supplied string (e.g. from the 'outputStyle' property) to an OutputStyle enum constant via the shortNames lookup table. If the name is not a registered short name (null result), it throws IllegalArgumentException. This guards against typo'd or unsupported output style names in configuration.

Solutions

  1. Use one of the registered short names exactly (check the OutputStyle enum / shortNames map, e.g. 'XML', 'INLINE_XML', 'TSV').
  2. Fix the case of the name; the lookup is exact-match, so match the enum's shortName string.
  3. Validate the style name against OutputStyle.values() shortNames before calling fromShortName.

Example fix

// before
OutputStyle style = OutputStyle.fromShortName("xml");
// after
OutputStyle style = OutputStyle.fromShortName("XML");
Defensive patterns

Strategy: validation

Validate before calling

boolean valid = java.util.Arrays.stream(PlainTextDocumentReaderAndWriter.OutputStyle.values())
    .anyMatch(s -> s.shortName.equals(name));

Try / catch

try {
  OutputStyle style = OutputStyle.fromShortName(name);
} catch (IllegalArgumentException e) {
  log.error("Unknown outputStyle '" + name + "', valid: " + Arrays.toString(OutputStyle.values()));
}

Prevention

When it happens

Trigger: Calling PlainTextDocumentReaderAndWriter.OutputStyle.fromShortName("...") with any string not in the shortNames map, e.g. 'xml' when only 'XML' is registered, or an arbitrary style name.

Common situations: Typo in -outputStyle command-line flag or Properties value; case mismatch ('tsv' vs 'Tsv' vs 'tabbed'); copying a style name from another NLP library's docs.

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/0afa0a5d11c9a11f. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/sequences/PlainTextDocumentReaderAndWriter.java:73

    }

    private static final Map<String, OutputStyle> shortNames = Generics.newHashMap();

    static {
      for (OutputStyle style : OutputStyle.values())
        shortNames.put(style.shortName, style);
    }

    /** Convert a String expressing an output format to its internal
     *  coding as an OutputStyle.
     *
     *  @param name The String name
     *  @return OutputStyle The internal constant
     */
    public static OutputStyle fromShortName(String name) {
      OutputStyle result = shortNames.get(name);
      if (result == null)
        throw new IllegalArgumentException(name + " is not an OutputStyle");
      return result;
    }

    public static boolean defaultToPreserveSpacing(String str) {
      return str.equals(XML.shortName) || str.equals(INLINE_XML.shortName);
    }

  } // end enum Output style

  private static final Pattern sgml = Pattern.compile("<[^>]*>");
  // TODO: allow for turning off splitting on . if we are processing already tokenized text
  private final WordToSentenceProcessor<IN> wts =
          new WordToSentenceProcessor<>(WordToSentenceProcessor.NewlineIsSentenceBreak.ALWAYS);

  private SeqClassifierFlags flags; // = null;
  private TokenizerFactory<IN> tokenizerFactory;

  /**

View on GitHub (pinned to 1b7edd19c4)