stanfordnlp/CoreNLP · error · IllegalArgumentException

getParenthesizedArg: Bad format String

Error message

getParenthesizedArg: Bad format String: ${str}

What it means

getParenthesizedArg extracts the Nth comma-separated argument from a feature-spec string that must be wrapped in parentheses, like feature(arg1,arg2). If the string contains no '(' before a ')' it is malformed and this IllegalArgumentException is thrown. It is the low-level parser used by extractor registration strings.

Solutions

  1. Rewrite the feature spec so arguments are enclosed in parentheses, e.g. 'wordshape(3)' not 'wordshape3'
  2. Ensure '(' appears before ')' in the string (no stray closing parenthesis)
  3. Inspect the exact string being passed at the call site (Extractor.arg / extractors property) for truncation
  4. Use getParenthesizedNum only for numeric specs and keep the same parenthesized format

Example fix

// before
String arg = "order-2,1"; // throws
// after
String arg = "order(-2,1)"; // well-formed
Defensive patterns

Strategy: validation

Validate before calling

if (spec.indexOf('(') < 0 || spec.lastIndexOf(')') <= spec.indexOf('(')) {
  throw new IllegalArgumentException("Feature spec must look like name(arg1,arg2): " + spec);
}

Try / catch

try {
  String arg = Extractor.getParenthesizedArg(spec, 1);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("Bad format String")) {
    // log the malformed spec and fail fast with a clearer message
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling Extractor.getParenthesizedArg(str, num) with a string lacking parentheses or with ')' before '(', e.g. passing 'order3' instead of 'order(3)' in an extractors configuration string.

Common situations: Typos in the tagger's 'extractors' or 'rareExtractor' feature spec; dropping the parentheses when editing a training properties file; whitespace/formatting corruption of the feature string.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/tagger/maxent/Extractor.java:254

    String args = (position == Integer.MAX_VALUE) ? "": (position + "," + (isTag ? "tag" : "word"));
    return cl.substring(ind + 1) + '(' + args + ')';
  }


  /** This is used for argument parsing in arch variable.
   *  It can extract from a comma separated values argument list.
   *  Values can be quoted with double quotes (with a second double quote as double quote escape char)
   *  like in a regular CSV file. It assumes the input format is "name(arg,arg,arg)".
   *
   *  @param str arch variable component input
   *  @param num Number of argument. Numbers are 1-indexed (i.e., start from 1 not 0)
   *  @return The parenthesized String, or null if none.
   */
  static String getParenthesizedArg(String str, int num) {
    int left = str.indexOf('(');
    int right = str.lastIndexOf(')');
    if (left < 0 || right <= left) {
      throw new IllegalArgumentException("getParenthesizedArg: Bad format String: " + str);
    }
    String argStr = str.substring(left + 1, right);
    String[] args = StringUtils.splitOnCharWithQuoting(argStr, ',', '"', '"');
    // log.info("getParenthesizedArg split " + str + " into " + args.length + " pieces; returning number " + num);
    // for (int i = 0; i < args.length; i++) {
    //   log.info("  " + args[i]);
    // }
    num--;
    if (args.length <= num || num < 0) {
      return null;
    }
    return args[num];
  }

  /** This is used for argument parsing in arch variable.
   *  It can extract a comma separated argument.
   *  Assumes the input format is "name(arg,arg,arg)", with possible
   *  spaces around the parentheses and comma(s).

View on GitHub (pinned to 1b7edd19c4)