{"record":{"id":"7c51a4423bed08d6","repo":"stanfordnlp/CoreNLP","slug":"chineseenglishwordmap-cannot-find-dictionary","errorCode":null,"errorMessage":"ChineseEnglishWordMap cannot find dictionary","messagePattern":"ChineseEnglishWordMap cannot find dictionary","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/edu/stanford/nlp/trees/international/pennchinese/CEDict.java","lineNumber":22,"sourceCode":"\npublic class CEDict {\n  private static final String defaultPath = \"cedict_ts.u8\";\n  private static final String defaultPath2 = \"/u/nlp/data/chinese-english-dictionary/cedict_ts.u8\";\n  private static final String ENV_VARIABLE = \"CEDICT\";\n\n  public static String path() {\n    File f = new File(defaultPath);\n    if (f.canRead()) {\n      return defaultPath;\n    } else {\n      f = new File(defaultPath2);\n      if (f.canRead()) {\n        return defaultPath2;\n      } else {\n        String path = System.getenv(ENV_VARIABLE);\n        f = new File(path);\n        if ( ! f.canRead()) {\n          throw new RuntimeException(\"ChineseEnglishWordMap cannot find dictionary\");\n        }\n        return path;\n      }\n    }\n  }\n\n  private CEDict() {} // static methods only\n}\n","sourceCodeStart":4,"sourceCodeEnd":31,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/international/pennchinese/CEDict.java#L4-L31","documentation":"CEDict backs ChineseEnglishWordMap with a dictionary file located via a default path and, failing that, an environment variable (ENV_VARIABLE). If neither location is readable, the static path() method throws a RuntimeException — the dictionary is mandatory, so initialization aborts. This is a class-loading/initialization-time failure: any use of ChineseEnglishWordMap hits it.","triggerScenarios":"Instantiating or statically touching ChineseEnglishWordMap/CEDict when the default dictionary path does not exist and the environment variable (CE_HOME-style) is unset or points to a non-readable file.","commonSituations":"Deploying to a machine where the CEDict data file was never installed; container images that omitted the data files; running after a library upgrade that changed the expected default path; environment variable renamed or not exported in the runtime shell.","solutions":["Set the environment variable expected by CEDict (ENV_VARIABLE, e.g. pointing at cedict data) to a readable dictionary file path","Place the dictionary file at the default path the class checks first (defaultPath/defaultPath2)","Verify file permissions with ls/File.canRead() — the file must be readable by the JVM process user","Reinstall/bundle the dictionary resource with the application (e.g. copy it into the deployment image) and catch the RuntimeException to surface a friendlier setup message"],"exampleFix":"// before\nWordMap wm = new ChineseEnglishWordMap(); // throws: cannot find dictionary\n\n// after\n// export CEDICT_HOME=/opt/data/cedict_ts.u8  (shell), or defensively:\ntry {\n  WordMap wm = new ChineseEnglishWordMap();\n} catch (RuntimeException e) {\n  throw new IllegalStateException(\"Install CEDict dictionary and set its env var\", e);\n}","handlingStrategy":"fallback","validationCode":"// fail fast at startup with a clear message\nString env = System.getenv(\"CEDICT_HOME\"); // the variable CEDict's ENV_VARIABLE expects\nif (env == null || !new File(env).canRead())\n  throw new IllegalStateException(\"Set CEDICT_HOME to a readable CEDict dictionary file\");","typeGuard":"static boolean cedictAvailable() {\n  String env = System.getenv(\"CEDICT_HOME\");\n  return env != null && new File(env).canRead();\n}","tryCatchPattern":"try {\n  ChineseEnglishWordMap map = new ChineseEnglishWordMap();\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"cannot find dictionary\")) {\n    throw new IllegalStateException(\"Missing CEDict dictionary: install file or set env var\", e);\n  }\n  throw e;\n}","preventionTips":["Install the CEDict dictionary in every environment (CI, containers) at a known path or env var","Use an entrypoint/startup check that validates dictionary readability before the app serves traffic","Avoid renaming the env variable between environments; document it in deployment config","Watch for library upgrades that change the default dictionary path; re-verify after dependency bumps"],"tags":["java","environment","classpath","missing-file"],"backgroundTag":"missing-env-var","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"}