{"record":{"id":"0164f2ac2e26090b","repo":"stanfordnlp/CoreNLP","slug":"tokensregexnerannotator-name-error-opening-the","errorCode":null,"errorMessage":"TokensRegexNERAnnotator ${name}: Error opening the common words file: ${commonWordsFile}","messagePattern":"TokensRegexNERAnnotator (.+?): Error opening the common words file: (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java","lineNumber":252,"sourceCode":"\n  public TokensRegexNERAnnotator(String name, Properties properties) {\n    String prefix = ! StringUtils.isNullOrEmpty(name) ? name + '.': \"\";\n    String backgroundSymbol = properties.getProperty(prefix + \"backgroundSymbol\", DEFAULT_BACKGROUND_SYMBOL);\n    String[] backgroundSymbols = COMMA_DELIMITERS_PATTERN.split(backgroundSymbol);\n    String mappingFiles = properties.getProperty(prefix + \"mapping\", DefaultPaths.DEFAULT_KBP_TOKENSREGEX_NER_SETTINGS);\n    String[] mappings = processListMappingFiles(mappingFiles);\n    String validPosRegex = properties.getProperty(prefix + \"validpospattern\");\n    this.posMatchType = PosMatchType.valueOf(properties.getProperty(prefix + \"posmatchtype\",\n            DEFAULT_POS_MATCH_TYPE.name()));\n    String commonWordsFile = properties.getProperty(prefix + \"commonWords\");\n    commonWords = new HashSet<>();\n    if (commonWordsFile != null) {\n      try (BufferedReader reader = IOUtils.readerFromString(commonWordsFile)) {\n        for (String line; (line = reader.readLine()) != null; ) {\n          commonWords.add(line);\n        }\n      } catch (IOException ex) {\n        throw new RuntimeIOException(\"TokensRegexNERAnnotator \" + name\n            + \": Error opening the common words file: \" + commonWordsFile, ex);\n      }\n    }\n\n    String headerProp = properties.getProperty(prefix + \"mapping.header\", defaultHeader);\n    boolean readHeaderFromFile = headerProp.equalsIgnoreCase(\"true\");\n    String[] annotationFieldnames = null;\n    String[] headerFields = null;\n    if (readHeaderFromFile) {\n      annotationFieldnames = StringUtils.EMPTY_STRING_ARRAY;\n      annotationFields = new ArrayList<>();\n      // Set the read header property of each file to true\n      for (int i = 0; i < mappings.length; i++) {\n        String mappingLine = mappings[i];\n        if ( ! mappingLine.contains(\"header\")) {\n          mappingLine = \"header=true, \" + mappingLine;\n          mappings[i] = mappingLine;\n        } else if ( ! Pattern.compile(\"header\\\\s*=\\\\s*true\").matcher(mappingLine.toLowerCase()).find()) {","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/TokensRegexNERAnnotator.java#L234-L270","documentation":"TokensRegexNERAnnotator reads the 'commonWords' option file (words ignored during NER matching). Opening it via IOUtils.readerFromString throws IOException on missing/unreadable files, which is wrapped in RuntimeIOException naming the annotator name and file path.","triggerScenarios":"Setting tokensregexner.<name>.commonWords (or the default prefix) to a file path or URL that does not exist, cannot be opened, or is not readable at annotation-construction time.","commonSituations":"Relative path resolved from a different working directory; resource file not packaged in the jar; typo in the filename; running in a container where the data files were not mounted.","solutions":["Verify the file exists at the exact path (use absolute paths during debugging).","If loading from classpath, use a path that IOUtils can resolve, e.g. prefix with the proper resource location, and confirm the resource is in the jar.","Check file read permissions for the process user.","Remove the commonWords option if you do not need a common-words suppression list."],"exampleFix":"// before\nprops.setProperty(\"tokensregexner.rules.commonWords\", \"data/common_words.txt\");\n// after (verify file exists, or use classpath resource)\nprops.setProperty(\"tokensregexner.rules.commonWords\", \"/etc/corenlp/common_words.txt\");","handlingStrategy":"validation","validationCode":"String cw = props.getProperty(\"tokensregexner.rules.commonWords\");\nif (cw != null && !cw.isEmpty() && !new File(cw).canRead() && getClass().getResource(cw) == null)\n  throw new IllegalStateException(\"commonWords file not readable: \" + cw);","typeGuard":"boolean readableResource(String path) { return new File(path).canRead() || Thread.currentThread().getContextClassLoader().getResource(path) != null; }","tryCatchPattern":"try { new TokensRegexNERAnnotator(props); } catch (RuntimeIOException e) { if (e.getMessage().contains(\"Error opening the common words file\")) { log.error(\"Missing commonWords file: \" + e.getMessage()); } throw e; }","preventionTips":["Use absolute paths or classpath resources for data files","Ship data files inside the deployment image/jar","Check canRead() on all configured file options at startup"],"tags":["java","ner","file-not-found","io","corenlp"],"backgroundTag":"file-open-failed","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"}