{"record":{"id":"76b6852c85023026","repo":"stanfordnlp/CoreNLP","slug":"error-compiling","errorCode":null,"errorMessage":"Error compiling ","messagePattern":"Error compiling ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/SequencePattern.java","lineNumber":191,"sourceCode":"  public SequenceMatchAction<T> getAction() {\n    return action;\n  }\n\n  public void setAction(SequenceMatchAction<T> action) {\n    this.action = action;\n  }\n\n  public int getTotalGroups() {\n    return totalGroups;\n  }\n\n  // Compiles string (regex) to NFA for doing pattern simulation\n  public static <T> SequencePattern<T> compile(Env env, String string) {\n    try {\n      Pair<PatternExpr, SequenceMatchAction<T>> p = env.parser.parseSequenceWithAction(env, string);\n      return new SequencePattern<>(string, p.first(), p.second());\n    } catch (Exception ex) {\n      throw new RuntimeException(\"Error compiling \" + string + \" using environment \" + env);\n    }\n    //throw new UnsupportedOperationException(\"Compile from string not implemented\");\n  }\n\n  protected static <T> SequencePattern<T> compile(SequencePattern.PatternExpr nodeSequencePattern) {\n    return new SequencePattern<>(nodeSequencePattern);\n  }\n\n  public SequenceMatcher<T> getMatcher(List<? extends T> tokens) {\n    return new SequenceMatcher<>(this, tokens);\n  }\n\n  public <OUT> OUT findNodePattern(Function<NodePattern<T>, OUT> filter) {\n    Queue<State> todo = new LinkedList<>();\n    Set<State> seen = new HashSet<>();\n    todo.add(root);\n    seen.add(root);\n    while (!todo.isEmpty()) {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/SequencePattern.java#L173-L209","documentation":"SequencePattern.compile(env, string) parses a TokensRegex pattern string with the environment's parser and wraps any exception thrown during parsing or construction in a RuntimeException 'Error compiling <string> using environment <env>'. The original cause is chained, so it indicates a malformed pattern or a bad environment (missing types/options).","triggerScenarios":"Calling SequencePattern.compile(env, patternString) where the string has invalid TokensRegex syntax, references unknown variables/types in the Env, or the parser throws for any reason (e.g. bad nested regex or action syntax).","commonSituations":"Typos in TokensRegex rule files, referencing variables not registered in the Env, loading rules across CoreNLP versions with changed syntax, or malformed expressions like unbalanced brackets.","solutions":["Read the chained cause (ex.getCause()) to find the actual syntax problem","Validate the pattern string syntax against TokensRegex grammar (balanced brackets, valid operators)","Register all referenced variables/NodePattern types in the Env before compiling","Compile rules with the same CoreNLP version they were written for","Catch RuntimeException around compile() to surface which rule string failed"],"exampleFix":"// before\nSequencePattern<CoreMap> p = SequencePattern.compile(env, \"([word: /foo/] )\"); // unbalanced paren\n// after\nSequencePattern<CoreMap> p = SequencePattern.compile(env, \"[word: /foo/]\");","handlingStrategy":"try-catch","validationCode":"// sanity checks before compile\nif (string == null || string.trim().isEmpty()) throw new IllegalArgumentException(\"Empty pattern\");\n// optionally check balanced brackets\nint depth = 0;\nfor (char c : string.toCharArray()) {\n  if (c == '(' || c == '[') depth++;\n  if (c == ')' || c == ']') depth--;\n  if (depth < 0) throw new IllegalArgumentException(\"Unbalanced brackets in: \" + string);\n}\nif (depth != 0) throw new IllegalArgumentException(\"Unbalanced brackets in: \" + string);","typeGuard":null,"tryCatchPattern":"try {\n  SequencePattern<CoreMap> p = SequencePattern.compile(env, ruleString);\n} catch (RuntimeException e) {\n  log.error(\"Error compiling rule: \" + ruleString, e.getCause());\n  throw new IllegalArgumentException(\"Bad TokensRegex rule: \" + ruleString, e);\n}","preventionTips":["Always log e.getCause() to see the real parse error","Register all Env variables before compiling","Pin the CoreNLP version rules were written against","Compile all rules at startup so failures surface early"],"tags":["java","pattern-compilation","tokensregex","regex"],"backgroundTag":"invalid-regex-pattern","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"}