{"record":{"id":"7319c32fbec8c468","repo":"stanfordnlp/CoreNLP","slug":"ioexception-reading-cedict-from-file","errorCode":null,"errorMessage":"IOException reading CEDict from file ","messagePattern":"IOException reading CEDict from file ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/international/pennchinese/ChineseEnglishWordMap.java","lineNumber":206,"sourceCode":"              if ( ! t.equals(\"\")) {\n                if ( ! oldtrans.contains(t)) {\n                  oldtrans.add(t);\n                }\n              }\n            }\n          } else {\n            Set<String> transList = new LinkedHashSet<>(Arrays.asList(trans));\n            String normW = normalize(word);\n            Set<String> normSet = normalize(transList);\n            if ( ! normW.equals(\"\") && normSet.size() > 0) {\n              map.put(normW, normSet);\n            }\n          }\n        }\n      }\n      infile.close();\n    } catch (IOException e) {\n      throw new RuntimeException(\"IOException reading CEDict from file \" + dictPath, e);\n    }\n  }\n\n  /**\n   * Make a ChineseEnglishWordMap with a default CEDict path.\n   * It looks for the file \"cedict_ts.u8\" in the working directory, for the\n   * value of the CEDICT environment variable, and in a Stanford NLP Group\n   * specific place.  It throws an exception if a dictionary cannot be found.\n   */\n  public ChineseEnglishWordMap() {\n    String path = CEDict.path();\n    readCEDict(path);\n  }\n\n  /**\n   * Make a ChineseEnglishWordMap\n   * @param dictPath the path/filename of the CEDict\n   */","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/international/pennchinese/ChineseEnglishWordMap.java#L188-L224","documentation":"ChineseEnglishWordMap.readCEDict parses the CEDict dictionary file (cedict_ts.u8) to build a Chinese-English mapping. If any IOException occurs while reading that file, the method wraps it in a RuntimeException naming the dictionary path, so a missing or unreadable CEDict file fails fast at map construction. The original IOException is chained as the cause.","triggerScenarios":"Constructing a ChineseEnglishWordMap (or calling readCEDict) when cedict_ts.u8 is absent from the working directory, the given dictPath is wrong, the file lacks read permissions, or is deleted mid-read.","commonSituations":"Deploying the library without bundling the CEDict data file, running from a different working directory than where cedict_ts.u8 was placed, or referencing a CEDict version whose filename differs.","solutions":["Place cedict_ts.u8 in the working directory or pass the correct dictPath to the ChineseEnglishWordMap constructor","Download CEDict from the official site if the file is missing","Check file permissions and that the process can read the path printed in the exception message","Inspect the chained cause (e.getCause()) to distinguish FileNotFoundException from other IO failures"],"exampleFix":"// before\nChineseEnglishWordMap map = new ChineseEnglishWordMap(); // fails if cedict_ts.u8 absent\n// after\nFile dict = new File(\"cedict_ts.u8\");\nif (!dict.canRead()) throw new IllegalStateException(\"Download cedict_ts.u8 to \" + dict.getAbsolutePath());\nChineseEnglishWordMap map = new ChineseEnglishWordMap(\"cedict_ts.u8\");","handlingStrategy":"try-catch","validationCode":"File dict = new File(dictPath);\nif (!dict.exists() || !dict.canRead())\n  throw new IllegalStateException(\"CEDict file missing/unreadable: \" + dict.getAbsolutePath());","typeGuard":null,"tryCatchPattern":"try {\n  ChineseEnglishWordMap map = new ChineseEnglishWordMap(dictPath);\n} catch (RuntimeException e) {\n  IOException ioe = (IOException) e.getCause();\n  // handle missing/unreadable CEDict: locate file or fail gracefully\n}","preventionTips":["Bundle cedict_ts.u8 with your deployment artifacts","Always run with the intended working directory or pass absolute dictPath","Check canRead() before constructing the map","Inspect the chained cause to distinguish file-not-found from other IO issues"],"tags":["java","io","dictionary","file"],"backgroundTag":"file-read-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}