stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException

Invalid value for key:

Error message

Invalid value  for key: 

What it means

Thrown by ComplexNodePattern.populate when parsing an attribute value string in a TokensRegex rule. Each value string is matched against prefixes like '>=', '>', '<=', '<' or a plain token pattern; if none match and no custom parser handled it, the value's syntax is unsupported for that annotation key. The message includes the offending value and attribute name.

Solutions

  1. Check the exact value string in the rule; it must start with >=, >, <=, < or match [A-Za-z0-9_+-.]+
  2. Register a custom parser for the key via env, or use a supported expression form
  3. Quote the value as a regex string pattern (e.g. /.../) if it was meant to match text

Example fix

// before (TokensRegex rule)
{ word:="5" }
// after
{ word:5 }
Defensive patterns

Strategy: validation

Validate before calling

private static final java.util.regex.Pattern OK = java.util.regex.Pattern.compile("[A-Za-z0-9_+-.]+");
boolean validValue(String v) { return v != null && (v.matches("(>=|<=|<|>).*") || OK.matcher(v).matches()); }
if (!validValue(value)) throw new IllegalArgumentException("Unsupported TokensRegex value: " + value);

Type guard

boolean isSupportedValueSyntax(String v) { return v != null && !v.isBlank() && (v.startsWith(">=") || v.startsWith("<=") || v.startsWith(">") || v.startsWith("<") || v.matches("[A-Za-z0-9_+-.]+")); }

Try / catch

try { p = ComplexNodePattern.valueOf(attr, value, env); } catch (IllegalArgumentException e) { log.error("Bad TokensRegex attribute value: {} -> {}", attr, value, e); throw new RuleSyntaxException(value); }

Prevention

When it happens

Trigger: Calling ComplexNodePattern.valueOf(attr, value, env) (or parsing a TokensRegex node expression) with a value string that is not a recognized prefix expression (e.g. '>5'), not a plain [A-Za-z0-9_+-.]+ token, and has no registered custom parser for the key.

Common situations: Typos in rule files (e.g. '= 5' with a space, '~5', empty string after '='), using regex-only syntax in a numeric context, or referencing a key without a custom parser for the value's format.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/ComplexNodePattern.java:104

              break;
            case "::EXISTS":
            case "::NOT_NIL":
              p.add(c, new NotNilAnnotationPattern());
              break;
            case "::IS_NUM":
              p.add(c, new NumericAnnotationPattern(0, NumericAnnotationPattern.CmpType.IS_NUM));
              break;
            default:
              boolean ok = false;
              if (env != null) {
                Object custom = env.get(value);
                if (custom != null) {
                  p.add(c, (NodePattern) custom);
                  ok = true;
                }
              }
              if (!ok) {
                throw new IllegalArgumentException("Invalid value " + value + " for key: " + attr);
              }
              break;
          }
        } else if (value.startsWith("<=")) {
          Double v = Double.parseDouble(value.substring(2));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.LE));
        } else if (value.startsWith(">=")) {
          Double v = Double.parseDouble(value.substring(2));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.GE));
        } else if (value.startsWith("==")) {
          Double v = Double.parseDouble(value.substring(2));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.EQ));
        } else if (value.startsWith("!=")) {
          Double v = Double.parseDouble(value.substring(2));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.NE));
        } else if (value.startsWith(">")) {
          Double v = Double.parseDouble(value.substring(1));
          p.add(c, new NumericAnnotationPattern(v, NumericAnnotationPattern.CmpType.GT));

View on GitHub (pinned to 1b7edd19c4)