stanfordnlp/CoreNLP · error · java.lang.Error

Invalid sequence pattern variable class:

Error message

Invalid sequence pattern variable class: 

What it means

Env.getSequencePatternExpr builds a SequencePattern from a variable's value. If the bound value is neither a String (parsed) nor an already-built SequencePattern, it throws 'Invalid sequence pattern variable class'. The library only supports those two value types for sequence-pattern variables.

Solutions

  1. Cast or convert the variable value to a String before binding it (e.g. String.valueOf(obj)) so it goes through parser.parseSequence
  2. If you already have a pattern, bind a SequencePattern object instead of an arbitrary type
  3. Inspect obj.getClass() at the throw site and fix the code that populated the Env variable with the wrong type

Example fix

// before
env.set("myvar", Arrays.asList("foo", "bar"));
// after
env.set("myvar", "[ { word:/foo|bar/ } ]"); // String parsed as SequencePattern
Defensive patterns

Strategy: validation

Validate before calling

Object v = env.get(name);
if (!(v instanceof String || v instanceof SequencePattern)) {
    throw new IllegalArgumentException(name + " must be a String or SequencePattern, got " + (v == null ? "null" : v.getClass().getName()));
}

Type guard

static boolean isValidSeqVarValue(Object v) { return v instanceof String || v instanceof SequencePattern; }

Try / catch

try { expr = env.getSequencePatternExpr(name); } catch (RuntimeException e) { LOG.error("Bad sequence variable: {}", e.getMessage()); throw new ConfigException(e); }

Prevention

When it happens

Trigger: Binding a TokensRegex environment variable (Env.set with a name bound to "$VAR" used in a sequence pattern) to an object that is not a String and not a SequencePattern, e.g. a List, Integer, or custom node type, then evaluating a pattern expression that references it via SeqVar.

Common situations: Loading patterns from config/property files where variable values are deserialized as generic Objects (Integer/Boolean instead of String); programmatically constructing Env variables with raw collections instead of pattern strings.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/Env.java:374

  public SequencePattern.PatternExpr getSequencePatternExpr(String name, boolean copy) {
    Object obj = variables.get(name);
    if (obj != null) {
      if (obj instanceof SequencePattern) {
        SequencePattern seqPattern = (SequencePattern) obj;
        return seqPattern.getPatternExpr();
      } else if (obj instanceof SequencePattern.PatternExpr) {
        SequencePattern.PatternExpr pe = (SequencePattern.PatternExpr) obj;
        return (copy)? pe.copy():pe;
      } else if (obj instanceof NodePattern) {
        return new SequencePattern.NodePatternExpr( (NodePattern) obj);
      } else if (obj instanceof String) {
        try {
          return parser.parseSequence(this, (String) obj);
        } catch (Exception pex) {
          throw new RuntimeException("Error parsing " + obj + " to sequence pattern", pex);
        }
      } else {
        throw new Error("Invalid sequence pattern variable class: " + obj.getClass());
      }
    }
    return null;
  }

  public Object get(String name)
  {
      return variables.get(name);
  }

  // Functions for storing temporary thread specific variables
  //  that are used when running tokensregex

  public void push(String name, Object value) {
    Map<String,Object> vars = threadLocalVariables.get();
    if (vars == null) {
      threadLocalVariables.set(vars = new HashMap<>()); //Generics.newHashMap());
    }

View on GitHub (pinned to 1b7edd19c4)