{"record":{"id":"c2ff16eba2e3c523","repo":"stanfordnlp/CoreNLP","slug":"generateparseexception","errorCode":null,"errorMessage":"generateParseException()","messagePattern":"generateParseException\\(\\)","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java","lineNumber":3833,"sourceCode":"\t else token = token.next = token_source.getNextToken();\n\t jj_ntk = -1;\n\t if (token.kind == kind) {\n\t   jj_gen++;\n\t   if (++jj_gc > 100) {\n\t\t jj_gc = 0;\n\t\t for (int i = 0; i < jj_2_rtns.length; i++) {\n\t\t   JJCalls c = jj_2_rtns[i];\n\t\t   while (c != null) {\n\t\t\t if (c.gen < jj_gen) c.first = null;\n\t\t\t c = c.next;\n\t\t   }\n\t\t }\n\t   }\n\t   return token;\n\t }\n\t token = oldToken;\n\t jj_kind = kind;\n\t throw generateParseException();\n  }\n\n  @SuppressWarnings(\"serial\")\n  static private final class LookaheadSuccess extends java.lang.Error {\n    @Override\n    public Throwable fillInStackTrace() {\n      return this;\n    }\n  }\n  static private final LookaheadSuccess jj_ls = new LookaheadSuccess();\n  private boolean jj_scan_token(int kind) {\n\t if (jj_scanpos == jj_lastpos) {\n\t   jj_la--;\n\t   if (jj_scanpos.next == null) {\n\t\t jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();\n\t   } else {\n\t\t jj_lastpos = jj_scanpos = jj_scanpos.next;\n\t   }","sourceCodeStart":3815,"sourceCodeEnd":3851,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/parser/TokenSequenceParser.java#L3815-L3851","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos in TokensRegex patterns; using syntax from a different CoreNLP version; unbalanced parentheses/brackets in pattern strings; invalid escape sequences.","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"],"exampleFix":"// before\nEnv env = TokenSequenceParser.parseNewEnv(p, \"[ { word:/a/ } ]\"); // unbalanced / bad syntax\n// after\nEnv env = TokenSequenceParser.parseNewEnv(p, \"[{word:/a/}]\"); // valid TokensRegex syntax","handlingStrategy":"try-catch","validationCode":"// Java: sanity-check TokensRegex pattern structure before parsing\nstatic boolean looksBalanced(String p) {\n  int b = 0, c = 0;\n  for (char ch : p.toCharArray()) {\n    if (ch == '[') b++; if (ch == ']') b--;\n    if (ch == '{') c++; if (ch == '}') c--;\n    if (b < 0 || c < 0) return false;\n  }\n  return b == 0 && c == 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  Env env = TokenSequenceParser.parseNewEnv(env0, pattern);\n} catch (ParseException e) {\n  throw new IllegalArgumentException(\"TokensRegex syntax error at token \" + e.currentToken + \": \" + pattern, e);\n}","preventionTips":["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"],"tags":["tokensregex","javacc","parse-exception"],"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-17T15:17:12.973Z"}