{"record":{"id":"da86ee5a38f8da3a","repo":"stanfordnlp/CoreNLP","slug":"unknown-language-lang","errorCode":null,"errorMessage":"Unknown language: ${lang}","messagePattern":"Unknown language: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java","lineNumber":1221,"sourceCode":"        return CoreNLPProtos.Language.UniversalChinese;\n      case English:\n        return CoreNLPProtos.Language.English;\n      case UniversalEnglish:\n        return CoreNLPProtos.Language.UniversalEnglish;\n      case German:\n        return CoreNLPProtos.Language.German;\n      case French:\n        return CoreNLPProtos.Language.French;\n      case Hebrew:\n        return CoreNLPProtos.Language.Hebrew;\n      case Spanish:\n        return CoreNLPProtos.Language.Spanish;\n      case Unknown:\n        return CoreNLPProtos.Language.Unknown;\n      case Any:\n        return CoreNLPProtos.Language.Any;\n      default:\n        throw new IllegalStateException(\"Unknown language: \" + lang);\n    }\n  }\n\n  /**\n   * Return a Protobuf operator from an OperatorSpec (Natural Logic).\n   */\n  public static CoreNLPProtos.Operator toProto(OperatorSpec op) {\n    return CoreNLPProtos.Operator.newBuilder()\n        .setName(op.instance.name()).setQuantifierSpanBegin(op.quantifierBegin).setQuantifierSpanEnd(op.quantifierEnd)\n        .setSubjectSpanBegin(op.subjectBegin).setSubjectSpanEnd(op.subjectEnd)\n        .setObjectSpanBegin(op.objectBegin).setObjectSpanEnd(op.objectEnd).build();\n  }\n\n  /**\n   * Return a Protobuf polarity from a CoreNLP Polarity (Natural Logic).\n   */\n  public static CoreNLPProtos.Polarity toProto(Polarity pol) {\n    return CoreNLPProtos.Polarity.newBuilder()","sourceCodeStart":1203,"sourceCodeEnd":1239,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java#L1203-L1239","documentation":"toProto converts a Language enum to its protobuf counterpart via a switch; if the switch hits an unmapped default (e.g. a newer Language constant not covered by the cases) it throws IllegalStateException 'Unknown language'.","triggerScenarios":"Serializing a document whose LanguageAnnotation value is a Language enum constant not handled by the switch — typically when mixing CoreNLP versions (document annotated with a newer language constant, serialized by an older serializer).","commonSituations":"Version mismatch between the jar that annotated the document and the jar serializing it; custom Language enum extensions; deserialized/resumed pipelines carrying languages added after the serializer's switch was written.","solutions":["Use matching CoreNLP versions for annotation and serialization","Extend the switch in toProto to map the new Language constant to its CoreNLPProtos.Language equivalent","Fall back to CoreNLPProtos.Language.Unknown for unmapped languages in custom serializer subclasses"],"exampleFix":"// before\ncase Any: return CoreNLPProtos.Language.Any;\ndefault: throw new IllegalStateException(\"Unknown language: \" + lang);\n// after\ncase Any: return CoreNLPProtos.Language.Any;\ncase Chinese: return CoreNLPProtos.Language.Chinese; // map the new constant\ndefault: return CoreNLPProtos.Language.Unknown; // graceful fallback","handlingStrategy":"try-catch","validationCode":"Language lang = doc.get(CoreAnnotations.LanguageAnnotation.class); if (lang != null && !SUPPORTED_LANGS.contains(lang)) { doc.set(CoreAnnotations.LanguageAnnotation.class, Language.Unknown); }","typeGuard":null,"tryCatchPattern":"try { proto = serializer.toProto(doc); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Unknown language\")) { doc.set(CoreAnnotations.LanguageAnnotation.class, Language.Unknown); proto = serializer.toProto(doc); } else throw e; }","preventionTips":["Keep the same CoreNLP version on all pipeline stages","Map new Language enum constants when upgrading before re-serializing old documents"],"tags":["java","serialization","protobuf","enum-mapping"],"backgroundTag":"unsupported-enum-value","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"}