{"record":{"id":"32965baa5188ac60","repo":"stanfordnlp/CoreNLP","slug":"error-creating-chinesemaxentlexicon-e","errorCode":null,"errorMessage":"Error creating ChineseMaxentLexicon{e}","messagePattern":"Error creating ChineseMaxentLexicon(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/ChineseMorphFeatureSets.java","lineNumber":43,"sourceCode":"  private Map<String, Pair<Set<Character>, Set<Character>>> affixFeatures = Generics.newHashMap();\n\n  public Map<String, Set<Character>> getSingletonFeatures() {\n    return singletonFeatures;\n  }\n\n  public Map<String, Pair<Set<Character>, Set<Character>>> getAffixFeatures() {\n    return affixFeatures;\n  }\n\n  public ChineseMorphFeatureSets(String featureDir) {\n    try {\n      File dir = new File(featureDir);\n      File[] files = dir.listFiles((dir1, name) -> name.endsWith(\".gb\"));\n      for (File file : files) {\n        getFeatures(file);\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(\"Error creating ChineseMaxentLexicon\" + e);\n    }\n  }\n\n  private enum FeatType {\n    PREFIX, SUFFIX, SINGLETON\n  }\n\n  private void getFeatures(File file) throws IOException {\n    BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), \"GB18030\"));\n    String filename = file.getName();\n    String singleFeatName = filename;\n    if (singleFeatName.indexOf('.') >= 0) {\n      singleFeatName = singleFeatName.substring(0, filename.lastIndexOf('.'));\n    }\n\n    FeatType featType = null;\n    for (FeatType ft : FeatType.values()) {\n      if (filename.contains(ft.toString().toLowerCase())) {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/ChineseMorphFeatureSets.java#L25-L61","documentation":"ChineseMorphFeatureSets' constructor scans a feature directory for .gb files and calls getFeatures on each; an IOException while reading any file is rethrown as a RuntimeException 'Error creating ChineseMaxentLexicon...'. It signals the morphological feature data could not be loaded from disk.","triggerScenarios":"Constructing ChineseMorphFeatureSets with a featureDir that does not exist, is unreadable, or whose .gb files fail I/O while being read (also note listFiles may return null and cause an NPE in the same try block).","commonSituations":"Wrong path to the Chinese morphological feature dictionary files; data files missing from deployment (not in classpath/resources); permission problems reading the directory.","solutions":["Verify the feature directory exists and contains .gb files","Check the wrapped IOException message for the exact failing file","Fix file permissions or copy the .gb feature files into the expected location","Use the correct path to the resources bundled with the model distribution"],"exampleFix":"// before\nnew ChineseMorphFeatureSets(\"/models/chinese-features\"); // dir missing\n// after\nFile dir = new File(\"/models/chinese-features\");\nif (!dir.isDirectory() || dir.listFiles((d,n)->n.endsWith(\".gb\")) == null)\n  throw new IllegalArgumentException(\"Feature dir missing or no .gb files: \" + dir);\nnew ChineseMorphFeatureSets(dir.getPath());","handlingStrategy":"try-catch","validationCode":"File dir = new File(featureDir);\nif (!dir.isDirectory()) throw new IllegalStateException(\"Missing feature dir: \" + featureDir);\nFile[] gb = dir.listFiles((d, n) -> n.endsWith(\".gb\"));\nif (gb == null || gb.length == 0) throw new IllegalStateException(\"No .gb feature files in \" + featureDir);","typeGuard":null,"tryCatchPattern":"try { fs = new ChineseMorphFeatureSets(featureDir); }\ncatch (RuntimeException e) { log.error(\"Feature load failed: {}\", e.getMessage(), e); throw new IllegalStateException(\"Fix chinese feature data path\", e); }","preventionTips":["Package .gb feature files with the model and resolve paths from the classpath","Check directory readability at startup","Pin the exact feature-data layout the library expects"],"tags":["io","file-not-found","chinese-nlp"],"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-15T23:17:13.987Z"}