{"record":{"id":"782ec023f9d7a120","repo":"infinilabs/analysis-ik","slug":"ik-analyzer-name-not-found","errorCode":null,"errorMessage":"ik-analyzer: \" + name + \" not found!!!","messagePattern":"ik-analyzer: \" \\+ name \\+ \" not found!!!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"core/src/main/java/org/wltea/analyzer/dic/Dictionary.java","lineNumber":209,"sourceCode":"\t}\r\n\r\n\tprivate void loadDictFile(DictSegment dict, Path file, boolean critical, String name) {\r\n\t\ttry (InputStream is = new FileInputStream(file.toFile())) {\r\n\t\t\tBufferedReader br = new BufferedReader(\r\n\t\t\t\t\tnew InputStreamReader(is, \"UTF-8\"), 512);\r\n\t\t\tString word = br.readLine();\r\n\t\t\tif (word != null) {\r\n\t\t\t\tif (word.startsWith(\"\\uFEFF\"))\r\n\t\t\t\t\tword = word.substring(1);\r\n\t\t\t\tfor (; word != null; word = br.readLine()) {\r\n\t\t\t\t\tword = word.trim();\r\n\t\t\t\t\tif (word.isEmpty()) continue;\r\n\t\t\t\t\tdict.fillSegment(word.toCharArray());\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} catch (FileNotFoundException e) {\r\n\t\t\tlogger.error(\"ik-analyzer: \" + name + \" not found\", e);\r\n\t\t\tif (critical) throw new RuntimeException(\"ik-analyzer: \" + name + \" not found!!!\", e);\r\n\t\t} catch (IOException e) {\r\n\t\t\tlogger.error(\"ik-analyzer: \" + name + \" loading failed\", e);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate List<String> getExtDictionarys() {\r\n\t\tList<String> extDictFiles = new ArrayList<String>(2);\r\n\t\tString extDictCfg = getProperty(EXT_DICT);\r\n\t\tif (extDictCfg != null) {\r\n\r\n\t\t\tString[] filePaths = extDictCfg.split(\";\");\r\n\t\t\tfor (String filePath : filePaths) {\r\n\t\t\t\tif (filePath != null && !\"\".equals(filePath.trim())) {\r\n\t\t\t\t\tPath file = configuration.getPath(getDictRoot(), filePath.trim());\r\n\t\t\t\t\twalkFileTree(extDictFiles, file);\r\n\r\n\t\t\t\t}\r\n\t\t\t}\r","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/infinilabs/analysis-ik/blob/6d2d70fd1a237cbf75cde254e8e4d6319b81266c/core/src/main/java/org/wltea/analyzer/dic/Dictionary.java#L191-L227","documentation":"While Dictionary.initial(Configuration) loads the IK dictionaries, loadDictFile wraps a FileNotFoundException in a RuntimeException when the file is marked critical (the built-in dictionaries such as main.dic and the stopword dict, unlike optional ext dictionaries). The message embeds the dictionary name that could not be opened. It aborts the whole initialization, so no working dictionary is left behind — segmentation is unavailable until the file is restored.","triggerScenarios":"Dictionary.initial(cfg) (or the first IKAnalyzer/IKTokenizer operation that triggers dictionary loading) with a critical .dic file absent from the resolved conf directory: conf_dir or the plugin config dir does not contain main.dic/stopword.dic, the path recorded in IKAnalyzer.cfg.xml resolves against the wrong working directory, or file permissions deny read so FileInputStream reports not-found/unopenable. Non-critical ext files only log; critical built-in files throw.","commonSituations":"Running IK Analyzer (often the Elasticsearch/Opensearch plugin form) outside its packaged layout: unzipping the plugin without the config/ directory, Docker images that copy the jar but not the dic files, IDE tests where the working directory is not the project root so relative conf paths break, case-sensitive filesystems mangling 'Main.dic' vs 'main.dic', and upgrades that restructured the config directory layout.","solutions":["Verify the dictionary file named in the message exists under the conf directory the logger printed ('try load config from ...') — restore it from the distribution zip if missing","Check IKAnalyzer.cfg.xml location and that its entries (main dict, stopword dict, ext paths) resolve relative to that directory; fix absolute/relative paths or the deployment working directory","Confirm read permission and exact case of the filename on case-sensitive filesystems (Linux) when packaging custom images","As a last resort in embedded usage, ship a minimal main.dic — an empty but present file passes the loader since empty lines are skipped"],"exampleFix":"# before: plugin deployed without its config directory\nplugins/ik-analyzer/*.jar   # no config/ -> RuntimeException on startup\n\n# after: restore the shipped config directory next to the jars\nplugins/ik-analyzer/config/IKAnalyzer.cfg.xml\nplugins/ik-analyzer/config/main.dic\nplugins/ik-analyzer/config/stopword.dic","handlingStrategy":"validation","validationCode":"Path confDir = configDir; // the directory you pass to your Configuration\nString[] criticalDicts = {\"main.dic\", \"stopword.dic\"};\nfor (String d : criticalDicts) {\n    if (!Files.isRegularFile(confDir.resolve(d)) || !Files.isReadable(confDir.resolve(d))) {\n        throw new IllegalStateException(\"missing critical dictionary: \" + confDir.resolve(d));\n    }\n}\nDictionary.initial(cfg);","typeGuard":null,"tryCatchPattern":"try {\n    Dictionary.initial(cfg);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"not found!!!\")) {\n        throw new IllegalStateException(\"IK dictionary files missing from config dir — check deployment layout\", e);\n    }\n    throw e;\n}","preventionTips":["Include the config/ directory (IKAnalyzer.cfg.xml plus all .dic files) in every artifact that ships the IK jar","Smoke-test deployments with a one-token analysis request before going live so init failures surface at rollout, not first query","Keep dictionary filenames lowercase and match case exactly on Linux/container filesystems","Pin the conf directory explicitly (absolute path or config-in-plugin-dir) instead of relying on the process working directory"],"tags":["java","ik-analyzer","configuration","file-not-found","deployment"],"backgroundTag":null,"analyzedSha":"6d2d70fd1a237cbf75cde254e8e4d6319b81266c","analyzedAt":"2026-08-14T14:39:54.684Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}