{"record":{"id":"5aa07c94b854c994","repo":"stanfordnlp/CoreNLP","slug":"getparenthesizedarg-bad-format-string-str","errorCode":null,"errorMessage":"getParenthesizedArg: Bad format String: ${str}","messagePattern":"getParenthesizedArg: Bad format String: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/tagger/maxent/Extractor.java","lineNumber":254,"sourceCode":"    String args = (position == Integer.MAX_VALUE) ? \"\": (position + \",\" + (isTag ? \"tag\" : \"word\"));\n    return cl.substring(ind + 1) + '(' + args + ')';\n  }\n\n\n  /** This is used for argument parsing in arch variable.\n   *  It can extract from a comma separated values argument list.\n   *  Values can be quoted with double quotes (with a second double quote as double quote escape char)\n   *  like in a regular CSV file. It assumes the input format is \"name(arg,arg,arg)\".\n   *\n   *  @param str arch variable component input\n   *  @param num Number of argument. Numbers are 1-indexed (i.e., start from 1 not 0)\n   *  @return The parenthesized String, or null if none.\n   */\n  static String getParenthesizedArg(String str, int num) {\n    int left = str.indexOf('(');\n    int right = str.lastIndexOf(')');\n    if (left < 0 || right <= left) {\n      throw new IllegalArgumentException(\"getParenthesizedArg: Bad format String: \" + str);\n    }\n    String argStr = str.substring(left + 1, right);\n    String[] args = StringUtils.splitOnCharWithQuoting(argStr, ',', '\"', '\"');\n    // log.info(\"getParenthesizedArg split \" + str + \" into \" + args.length + \" pieces; returning number \" + num);\n    // for (int i = 0; i < args.length; i++) {\n    //   log.info(\"  \" + args[i]);\n    // }\n    num--;\n    if (args.length <= num || num < 0) {\n      return null;\n    }\n    return args[num];\n  }\n\n  /** This is used for argument parsing in arch variable.\n   *  It can extract a comma separated argument.\n   *  Assumes the input format is \"name(arg,arg,arg)\", with possible\n   *  spaces around the parentheses and comma(s).","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/tagger/maxent/Extractor.java#L236-L272","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rewrite the feature spec so arguments are enclosed in parentheses, e.g. 'wordshape(3)' not 'wordshape3'","Ensure '(' appears before ')' in the string (no stray closing parenthesis)","Inspect the exact string being passed at the call site (Extractor.arg / extractors property) for truncation","Use getParenthesizedNum only for numeric specs and keep the same parenthesized format"],"exampleFix":"// before\nString arg = \"order-2,1\"; // throws\n// after\nString arg = \"order(-2,1)\"; // well-formed","handlingStrategy":"validation","validationCode":"if (spec.indexOf('(') < 0 || spec.lastIndexOf(')') <= spec.indexOf('(')) {\n  throw new IllegalArgumentException(\"Feature spec must look like name(arg1,arg2): \" + spec);\n}","typeGuard":null,"tryCatchPattern":"try {\n  String arg = Extractor.getParenthesizedArg(spec, 1);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Bad format String\")) {\n    // log the malformed spec and fail fast with a clearer message\n  } else { throw e; }\n}","preventionTips":["Always wrap feature arguments in parentheses: name(a,b)","Validate extractor spec strings at config-load time with a regex like ^\\w+\\(.*\\)$","Watch for truncation when building spec strings programmatically","Log the full spec string on parse failure"],"tags":["java","pos-tagger","string-parsing","format"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}