{"record":{"id":"ba623eeff61d8d42","repo":"stanfordnlp/CoreNLP","slug":"can-t-open-file-e-getmessage","errorCode":null,"errorMessage":"can't open file: ${e.getMessage()}","messagePattern":"can't open file: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/edu/stanford/nlp/tagger/maxent/CtbDict.java","lineNumber":30,"sourceCode":"public class CtbDict {\n\n  private static final String defaultFilename = \"ctb_dict.txt\";\n  private static CtbDict ctbDictSingleton;\n\n\n  private static synchronized CtbDict getInstance() {\n    if (ctbDictSingleton == null) {\n      ctbDictSingleton = new CtbDict();\n    }\n    return ctbDictSingleton;\n  }\n\n\n  private CtbDict() {\n    try {\n      readCtbDict(\"/u/nlp/data/pos-tagger/dictionary\" + '/' + defaultFilename);\n    } catch(IOException e) {\n      throw new RuntimeException(\"can't open file: \" + e.getMessage());\n      /* java sucks */\n    }\n  }\n\n\n  public Map <String, Set <String>> ctb_pre_dict;\n  public Map <String, Set <String>> ctb_suf_dict;\n\n\n  private void readCtbDict(String filename) throws IOException {\n    BufferedReader ctbDetectorReader = new BufferedReader(new InputStreamReader(new FileInputStream(filename), \"GB18030\"));\n    String ctbDetectorLine;\n\n    ctb_pre_dict = Generics.newHashMap();\n    ctb_suf_dict = Generics.newHashMap();\n\n    while ((ctbDetectorLine = ctbDetectorReader.readLine()) != null) {\n      String[] fields = ctbDetectorLine.split(\"\t\");","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/tagger/maxent/CtbDict.java#L12-L48","documentation":"The private CtbDict constructor loads the Chinese Treebank dictionary file from a hardcoded path on the NLP group's machines (/u/nlp/data/pos-tagger/dictionary). If that file cannot be read, the IOException is wrapped in a RuntimeException with the underlying message. This means the Chinese dictionary feature is unavailable in your environment.","triggerScenarios":"Instantiating the singleton CtbDict (via CtbDict.getInstance()) when readCtbDict() fails to open the hardcoded dictionary path, e.g. the file does not exist or is unreadable on a machine outside the Stanford NLP network.","commonSituations":"Running the POS tagger with Chinese dictionary features on a server/cluster that lacks /u/nlp/data; a Stanford-internal path that external users never have; permission problems on the data directory.","solutions":["Create the directory /u/nlp/data/pos-tagger/dictionary and place the CTB dictionary file (defaultFilename) there, or symlink it to where your data lives","Retrain/run the tagger without Chinese dictionary features (do not enable dictionary-based extractors) so CtbDict is never instantiated","Patch readCtbDict to load the dictionary from a configurable path or classpath resource instead of the hardcoded absolute path","Check file permissions on the dictionary file so the JVM user can read it"],"exampleFix":"// before: hardcoded path fails\nprivate CtbDict() {\n  try {\n    readCtbDict(\"/u/nlp/data/pos-tagger/dictionary\" + '/' + defaultFilename);\n  } catch(IOException e) {\n    throw new RuntimeException(\"can't open file: \" + e.getMessage());\n  }\n}\n// after: configurable path with classpath fallback\nprivate CtbDict() {\n  String dir = System.getProperty(\"ctbDictPath\", \"/u/nlp/data/pos-tagger/dictionary\");\n  try {\n    readCtbDict(dir + '/' + defaultFilename);\n  } catch(IOException e) {\n    throw new RuntimeException(\"can't open file: \" + dir + '/' + defaultFilename, e);\n  }\n}","handlingStrategy":"validation","validationCode":"File dict = new File(\"/u/nlp/data/pos-tagger/dictionary/ChineseDictionary.txt\");\nif (!dict.canRead()) {\n  throw new IllegalStateException(\"CTB dictionary missing/unreadable: \" + dict);\n}","typeGuard":null,"tryCatchPattern":"try {\n  CtbDict.getInstance();\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"can't open file:\")) {\n    // disable Chinese dictionary features or supply the dictionary\n  } else { throw e; }\n}","preventionTips":["Provision the hardcoded /u/nlp dictionary path (or symlink) before enabling Chinese dictionary features","Only enable Chinese dictionary extractors when you know the data files exist","Check file readability of the dictionary under the JVM's user account","Prefer a patched build that loads dictionaries from a configurable location"],"tags":["java","file-not-found","pos-tagger","hardcoded-path"],"backgroundTag":"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"}