stanfordnlp/CoreNLP · error · ParseException
generateParseException()
Error message
generateParseException()
What it means
TokenSequenceParser (JavaCC-generated) throws the ParseException produced by generateParseException() when token consumption fails inside jj_3 routines/backtracking. The "message" here is literally "generateParseException()" because the log/throw site stringifies the call; the real detail is in the generated ParseException describing the token choices that failed at the parse position.
Solutions
- Read the full ParseException (or its getMessage()) for the offending token and expected alternatives
- Fix the TokensRegex pattern at the indicated position — balance brackets and check escapes
- Test the pattern in small increments to isolate the failing fragment
- Verify the pattern syntax against the TokensRegex documentation for your CoreNLP version
Example fix
// before
Env env = TokenSequenceParser.parseNewEnv(p, "[ { word:/a/ } ]"); // unbalanced / bad syntax
// after
Env env = TokenSequenceParser.parseNewEnv(p, "[{word:/a/}]"); // valid TokensRegex syntax Defensive patterns
Strategy: try-catch
Validate before calling
// Java: sanity-check TokensRegex pattern structure before parsing
static boolean looksBalanced(String p) {
int b = 0, c = 0;
for (char ch : p.toCharArray()) {
if (ch == '[') b++; if (ch == ']') b--;
if (ch == '{') c++; if (ch == '}') c--;
if (b < 0 || c < 0) return false;
}
return b == 0 && c == 0;
} Try / catch
try {
Env env = TokenSequenceParser.parseNewEnv(env0, pattern);
} catch (ParseException e) {
throw new IllegalArgumentException("TokensRegex syntax error at token " + e.currentToken + ": " + pattern, e);
} Prevention
- Build complex TokensRegex patterns incrementally, testing each fragment
- Balance [], {}, and () carefully; escapes in Java strings need double backslashes
- Check the version-appropriate TokensRegex documentation for relation syntax
- Catch ParseException and surface its getMessage() for the real token-level detail
When it happens
Trigger: Calling TokensRegex parsing APIs (TokenSequenceParser.compile...) with a pattern string whose syntax doesn't match the grammar at some token — invalid regex constructs, unbalanced brackets/braces, bad relation syntax in a TokensRegex expression.
Common situations: Typos in TokensRegex patterns; using syntax from a different CoreNLP version; unbalanced parentheses/brackets in pattern strings; invalid escape sequences.
Related errors
- Parsing failed. Error:
- 2 arguments expected, got
- Annotation field cannot be null
- : Entry has multiple types for : . Taking type to be
- Attribute already defined:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/c2ff16eba2e3c523.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java:3833
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
if (++jj_gc > 100) {
jj_gc = 0;
for (int i = 0; i < jj_2_rtns.length; i++) {
JJCalls c = jj_2_rtns[i];
while (c != null) {
if (c.gen < jj_gen) c.first = null;
c = c.next;
}
}
}
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
@SuppressWarnings("serial")
static private final class LookaheadSuccess extends java.lang.Error {
@Override
public Throwable fillInStackTrace() {
return this;
}
}
static private final LookaheadSuccess jj_ls = new LookaheadSuccess();
private boolean jj_scan_token(int kind) {
if (jj_scanpos == jj_lastpos) {
jj_la--;
if (jj_scanpos.next == null) {
jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
} else {
jj_lastpos = jj_scanpos = jj_scanpos.next;
}View on GitHub (pinned to 1b7edd19c4)