{"record":{"id":"5806951fd080eaba","repo":"stanfordnlp/CoreNLP","slug":"invalid-sequence-pattern-variable-class","errorCode":null,"errorMessage":"Invalid sequence pattern variable class: ","messagePattern":"Invalid sequence pattern variable class: ","errorType":"exception","errorClass":"java.lang.Error","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/Env.java","lineNumber":374,"sourceCode":"  public SequencePattern.PatternExpr getSequencePatternExpr(String name, boolean copy) {\n    Object obj = variables.get(name);\n    if (obj != null) {\n      if (obj instanceof SequencePattern) {\n        SequencePattern seqPattern = (SequencePattern) obj;\n        return seqPattern.getPatternExpr();\n      } else if (obj instanceof SequencePattern.PatternExpr) {\n        SequencePattern.PatternExpr pe = (SequencePattern.PatternExpr) obj;\n        return (copy)? pe.copy():pe;\n      } else if (obj instanceof NodePattern) {\n        return new SequencePattern.NodePatternExpr( (NodePattern) obj);\n      } else if (obj instanceof String) {\n        try {\n          return parser.parseSequence(this, (String) obj);\n        } catch (Exception pex) {\n          throw new RuntimeException(\"Error parsing \" + obj + \" to sequence pattern\", pex);\n        }\n      } else {\n        throw new Error(\"Invalid sequence pattern variable class: \" + obj.getClass());\n      }\n    }\n    return null;\n  }\n\n  public Object get(String name)\n  {\n      return variables.get(name);\n  }\n\n  // Functions for storing temporary thread specific variables\n  //  that are used when running tokensregex\n\n  public void push(String name, Object value) {\n    Map<String,Object> vars = threadLocalVariables.get();\n    if (vars == null) {\n      threadLocalVariables.set(vars = new HashMap<>()); //Generics.newHashMap());\n    }","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/Env.java#L356-L392","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Cast or convert the variable value to a String before binding it (e.g. String.valueOf(obj)) so it goes through parser.parseSequence","If you already have a pattern, bind a SequencePattern object instead of an arbitrary type","Inspect obj.getClass() at the throw site and fix the code that populated the Env variable with the wrong type"],"exampleFix":"// before\nenv.set(\"myvar\", Arrays.asList(\"foo\", \"bar\"));\n// after\nenv.set(\"myvar\", \"[ { word:/foo|bar/ } ]\"); // String parsed as SequencePattern","handlingStrategy":"validation","validationCode":"Object v = env.get(name);\nif (!(v instanceof String || v instanceof SequencePattern)) {\n    throw new IllegalArgumentException(name + \" must be a String or SequencePattern, got \" + (v == null ? \"null\" : v.getClass().getName()));\n}","typeGuard":"static boolean isValidSeqVarValue(Object v) { return v instanceof String || v instanceof SequencePattern; }","tryCatchPattern":"try { expr = env.getSequencePatternExpr(name); } catch (RuntimeException e) { LOG.error(\"Bad sequence variable: {}\", e.getMessage()); throw new ConfigException(e); }","preventionTips":["Always bind sequence variables as String pattern text or SequencePattern objects","Log variable classes when loading pattern configs","Unit-test pattern/variable loading from config files"],"tags":["tokensregex","type-mismatch","pattern-parsing"],"backgroundTag":"type-mismatch","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"}