{"record":{"id":"220a4905f3dcbab6","repo":"stanfordnlp/CoreNLP","slug":"error-parsing-file","errorCode":null,"errorMessage":"Error parsing file: ","messagePattern":"Error parsing file: ","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/CoreMapExpressionExtractor.java","lineNumber":294,"sourceCode":"    return createExtractorFromFiles(env, Arrays.asList(filenames));\n  }\n\n  /**\n   * Creates an extractor using the specified environment, and reading the rules from the given filenames.\n   * @param env\n   * @param filenames\n   * @throws RuntimeException\n   */\n  public static <M extends MatchedExpression> CoreMapExpressionExtractor<M> createExtractorFromFiles(Env env, List<String> filenames) throws RuntimeException {\n    CoreMapExpressionExtractor<M> extractor = new CoreMapExpressionExtractor<>(env);\n    for (String filename:filenames) {\n      try (BufferedReader br = IOUtils.readerFromString(filename)) {\n        if (verbose)\n          log.info(\"Reading TokensRegex rules from \" + filename);\n        TokenSequenceParser parser = new TokenSequenceParser();\n        parser.updateExpressionExtractor(extractor, br);\n      } catch (Exception ex) {\n        throw new RuntimeException(\"Error parsing file: \" + filename, ex);\n      }\n    }\n    return extractor;\n  }\n\n  /**\n   * Creates an extractor using the specified environment, and reading the rules from the given filename.\n   * @param env\n   * @param filename\n   * @throws RuntimeException\n   */\n  public static CoreMapExpressionExtractor createExtractorFromFile(Env env, String filename) throws RuntimeException {\n    return createExtractorFromFiles(env, Collections.singletonList(filename));\n  }\n\n  /**\n   * Creates an extractor using the specified environment, and reading the rules from the given string\n   * @param env","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/CoreMapExpressionExtractor.java#L276-L312","documentation":"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.","triggerScenarios":"Calling CoreMapExpressionExtractor.createExtractorFromFiles(env, filenames) where a rules file has TokensRegex syntax errors, cannot be read, or the parser (TokenSequenceParser) rejects a construct.","commonSituations":"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.","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"],"exampleFix":"// before: cause hidden\ntry { extractor = createExtractorFromFiles(env, files); } catch (RuntimeException e) { e.printStackTrace(); }\n// after\ntry { extractor = createExtractorFromFiles(env, files); } catch (RuntimeException e) { logger.error(\"rule parse failed\", e.getCause()); }","handlingStrategy":"try-catch","validationCode":"File f = new File(rulesPath);\nif (!f.canRead()) throw new IOException(\"Rules file not readable: \" + rulesPath);\n// optional pre-check: file non-empty\nif (f.length() == 0) throw new IOException(\"Empty rules file: \" + rulesPath);","typeGuard":null,"tryCatchPattern":"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); }","preventionTips":["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"],"tags":["tokensregex","rules-file","parsing"],"backgroundTag":"config-file-not-found","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"}