{"record":{"id":"25807ecb0e78db8b","repo":"stanfordnlp/CoreNLP","slug":"character","errorCode":null,"errorMessage":"Character ","messagePattern":"Character ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/international/pennchinese/TraditionalSimplifiedCharacterMap.java","lineNumber":90,"sourceCode":"        String simplified = transform[1];\n        map.put(traditional, simplified);\n      }\n\n      String line;\n      while ((line = reader.readLine()) != null) {\n        if (line.startsWith(\"#\")) {\n          continue;\n        }\n        if (line.length() >= 3 &&\n            line.charAt(1) == ' ' && line.charAt(3) == ' ') {\n          // We're only interested in lines that represent a single character\n          String traditional = line.substring(0, 1);\n          String simplified = line.substring(2, 3);\n          // Fail on duplicates.  Only a few come up in cedict, and\n          // those that do should already be accommodated\n          if (map.containsKey(traditional) && !hardcodedSet.contains(traditional) &&\n              !simplified.equals(map.get(traditional))) {\n            throw new RuntimeException(\"Character \" + traditional + \" mapped to \" +\n                                       simplified + \" already mapped to \" +\n                                       map.get(traditional));\n          }\n          map.put(traditional, simplified);\n        }\n      }\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    }\n  }\n\n  public String apply(String input) {\n    StringBuilder translated = new StringBuilder();\n    for (int i = 0; i < input.length(); ++i) {\n      String c = input.substring(i, i + 1);\n      if (map.containsKey(c)) {\n        translated.append(map.get(c));\n      } else {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/international/pennchinese/TraditionalSimplifiedCharacterMap.java#L72-L108","documentation":"TraditionalSimplifiedCharacterMap.init() loads a traditional-to-simplified mapping file (cedict-derived) and fails if the same traditional character appears twice with a different simplified target, unless that character is in the hardcoded exception set. This guards against a corrupt or unexpectedly changed mapping file silently overwriting an entry.","triggerScenarios":"Loading a mapping resource where a line 'T<TAB>S' defines a traditional character that was already mapped to a different simplified character and is not whitelisted in hardcodedSet.","commonSituations":"Regenerating or hand-editing the cedict-derived mapping file and introducing duplicate keys; merging custom mappings with the shipped file; an upstream cedict data update conflicting with entries the library already hardcodes.","solutions":["Find the reported traditional character in the mapping file and remove or correct the conflicting duplicate line","If the duplicate is legitimate, add the traditional character to hardcodedSet so it is allowed","Diff your mapping file against the version shipped with the library to spot unintended additions","Deduplicate the source cedict export before regenerating the mapping"],"exampleFix":"// before (mapping file)\n龍 龙\n龍 龙2\n// after\n龍 龙  // keep exactly one entry per traditional character","handlingStrategy":"validation","validationCode":"Set<String> seen = new java.util.HashSet<>();\nfor (String line : java.nio.file.Files.readAllLines(mappingFile)) {\n  if (line.isBlank() || line.startsWith(\"#\")) continue;\n  String t = line.substring(0, 1);\n  if (!seen.add(t)) throw new IllegalStateException(\"Duplicate traditional char in mapping file: \" + t);\n}","typeGuard":null,"tryCatchPattern":"try {\n  map = new TraditionalSimplifiedCharacterMap(resource);\n} catch (RuntimeException e) {\n  log.error(\"Mapping file has duplicate/conflicting entry: \" + e.getMessage());\n  throw new IOException(\"Corrupt traditional-simplified mapping\", e);\n}","preventionTips":["Deduplicate the source cedict export before regenerating the mapping file","Diff custom mapping files against the shipped resource before deploying","Keep hardcodedSet in sync when adding intentional exceptions"],"tags":["java","duplicate-key","data-loading","chinese-nlp"],"backgroundTag":"schema-validation-failed","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"}