stanfordnlp/CoreNLP · error · java.lang.RuntimeException
Error parsing file:
Error message
Error parsing file:
What it means
createExtractorFromFiles wraps any exception raised while reading and parsing a TokensRegex rules file into a RuntimeException with this message. It is a generic wrapper: the cause (ex) holds the real parser error, usually a syntax error in the .rules file.
Solutions
- Inspect the cause exception (ex.getCause()) for the exact line/column of the grammar error
- Validate the rules file syntax ( braces, semicolons, rule options) against TokensRegex grammar
- Verify the file path is readable and the classpath/resource string is correct
- Check rule constructs against your CoreNLP version's grammar
Example fix
// before: cause hidden
try { extractor = createExtractorFromFiles(env, files); } catch (RuntimeException e) { e.printStackTrace(); }
// after
try { extractor = createExtractorFromFiles(env, files); } catch (RuntimeException e) { logger.error("rule parse failed", e.getCause()); } Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(rulesPath);
if (!f.canRead()) throw new IOException("Rules file not readable: " + rulesPath);
// optional pre-check: file non-empty
if (f.length() == 0) throw new IOException("Empty rules file: " + rulesPath); Try / catch
try { extractor = CoreMapExpressionExtractor.getExtractorFromFiles(env, files); } catch (RuntimeException e) { Throwable cause = e.getCause(); throw new IllegalStateException("TokensRegex rule parse failed: " + (cause != null ? cause.getMessage() : e.getMessage()), cause); } Prevention
- Always log/print the cause chain, not just the wrapper message
- Version-control and syntax-check rules files
- Test rules on a small corpus before production use
When it happens
Trigger: Calling CoreMapExpressionExtractor.createExtractorFromFiles(env, filenames) where a rules file has TokensRegex syntax errors, cannot be read, or the parser (TokenSequenceParser) rejects a construct.
Common situations: Malformed rule grammar (missing braces/semicolons), undefined variables or options in the rules file, wrong file path/encoding, or rules written for a different CoreNLP version.
Understand the failure class
Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.
Related errors
- Invalid value for key:
- Unknown annotation key:
- Error parsing to node pattern
- Error parsing to sequence pattern
- Parsing failed. Error:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/220a4905f3dcbab6.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/CoreMapExpressionExtractor.java:294
return createExtractorFromFiles(env, Arrays.asList(filenames));
}
/**
* Creates an extractor using the specified environment, and reading the rules from the given filenames.
* @param env
* @param filenames
* @throws RuntimeException
*/
public static <M extends MatchedExpression> CoreMapExpressionExtractor<M> createExtractorFromFiles(Env env, List<String> filenames) throws RuntimeException {
CoreMapExpressionExtractor<M> extractor = new CoreMapExpressionExtractor<>(env);
for (String filename:filenames) {
try (BufferedReader br = IOUtils.readerFromString(filename)) {
if (verbose)
log.info("Reading TokensRegex rules from " + filename);
TokenSequenceParser parser = new TokenSequenceParser();
parser.updateExpressionExtractor(extractor, br);
} catch (Exception ex) {
throw new RuntimeException("Error parsing file: " + filename, ex);
}
}
return extractor;
}
/**
* Creates an extractor using the specified environment, and reading the rules from the given filename.
* @param env
* @param filename
* @throws RuntimeException
*/
public static CoreMapExpressionExtractor createExtractorFromFile(Env env, String filename) throws RuntimeException {
return createExtractorFromFiles(env, Collections.singletonList(filename));
}
/**
* Creates an extractor using the specified environment, and reading the rules from the given string
* @param envView on GitHub (pinned to 1b7edd19c4)