{"record":{"id":"99ad6d7f2f94ba5b","repo":"stanfordnlp/CoreNLP","slug":"unknown-rule-type","errorCode":null,"errorMessage":"Unknown rule type: ","messagePattern":"Unknown rule type: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/SequenceMatchRules.java","lineNumber":338,"sourceCode":"    Map<String, Object> attributes;\n    cv = cv.simplifyNoTypeConversion(env);\n    attributes = new HashMap<>();//Generics.newHashMap();\n    for (String s:cv.getAttributes()) {\n      attributes.put(s, cv.getExpression(s));\n    }\n    return createExtractionRule(env, attributes);\n  }\n\n  protected static AnnotationExtractRule createExtractionRule(Env env, Map<String,Object> attributes) {\n    String ruleType = (String) Expressions.asObject(env, attributes.get(\"ruleType\"));\n    if (ruleType == null && env != null) {\n      ruleType = (String) env.getDefaults().get(\"ruleType\");\n    }\n    AnnotationExtractRuleCreator ruleCreator = lookupExtractRuleCreator(env, ruleType);\n    if (ruleCreator != null) {\n      return ruleCreator.create(env, attributes);\n    } else {\n      throw new IllegalArgumentException(\"Unknown rule type: \" + ruleType);\n    }\n  }\n\n  public static AnnotationExtractRule createExtractionRule(Env env, String ruleType, Object pattern, Expression result) {\n    if (ruleType == null && env != null) {\n      ruleType = (String) env.getDefaults().get(\"ruleType\");\n    }\n    AnnotationExtractRuleCreator ruleCreator = lookupExtractRuleCreator(env, ruleType);\n    if (ruleCreator != null) {\n      Map<String,Object> attributes = new HashMap<>();//Generics.newHashMap();\n      attributes.put(\"ruleType\", ruleType);\n      attributes.put(\"pattern\", pattern);\n      attributes.put(\"result\", result);\n      return ruleCreator.create(env, attributes);\n    } else {\n      throw new IllegalArgumentException(\"Unknown rule type: \" + ruleType);\n    }\n  }","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/SequenceMatchRules.java#L320-L356","documentation":"SequenceMatchRules.createRule looks up an AnnotationExtractRuleCreator registered in the Env for the given ruleType. When no creator is registered for the resolved rule type (ruleType attribute or env default), it throws IllegalArgumentException 'Unknown rule type: <type>'. The library only knows built-in types like 'composite', 'tokens', 'text'.","triggerScenarios":"Creating a rule with attributes.put(\"ruleType\", \"regex\") (or any unregistered string) and calling SequenceMatchRules.createRule(env, attributes); a typo such as 'token' instead of 'tokens'; env defaults setting a ruleType with no registered creator.","commonSituations":"Typo in a TokensRegex rules file's ruleType field; using a custom rule type without calling SequenceMatchRules.registerExtractRuleCreator; copying rule syntax from another library.","solutions":["Use a built-in rule type: \"composite\", \"tokens\", or \"text\"","Check spelling of the ruleType value in the rule file/attribute map","Register a custom creator first via SequenceMatchRules.registerExtractRuleCreator(env, type, creator)","Remove or correct a wrong ruleType in env.getDefaults()"],"exampleFix":"// before\nattributes.put(\"ruleType\", \"token\"); // unknown\n// after\nattributes.put(\"ruleType\", SequenceMatchRules.TOKEN_PATTERN_RULE_TYPE); // \"tokens\"","handlingStrategy":"validation","validationCode":"Object rt = attributes.get(\"ruleType\");\nif (rt != null && !Set.of(\"composite\",\"tokens\",\"text\").contains(rt)\n    && SequenceMatchRules.lookupExtractRuleCreator(env, (String) rt) == null) {\n  throw new IllegalArgumentException(\"Unregistered ruleType: \" + rt);\n}","typeGuard":null,"tryCatchPattern":"try {\n  rule = SequenceMatchRules.createRule(env, attributes);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unknown rule type\")) {\n    // log the offending ruleType and fall back to a built-in type\n  }\n}","preventionTips":["Only use built-in ruleType values: composite, tokens, text","Register custom creators before parsing rules","Spell-check ruleType strings in rule files","Check env defaults for a stale ruleType"],"tags":["java","tokensregex","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}