{"record":{"id":"2702a491e56a99cc","repo":"stanfordnlp/CoreNLP","slug":"error-failed-to-load-treebanklanguagepack-tlpc","errorCode":null,"errorMessage":"Error: Failed to load TreebankLanguagePack: ${tlpCanonicalName}","messagePattern":"Error: Failed to load TreebankLanguagePack: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/parser/nndep/DependencyParser.java","lineNumber":535,"sourceCode":"\n  void loadModelFile(String modelFile, boolean verbose) {\n    Timing t = new Timing();\n    try (BufferedReader input = IOUtils.readerFromString(modelFile)) {\n\n      // first line in newer saved models is language, legacy models don't store this\n      String s = input.readLine();\n      // check if language was stored\n      if (isModelNewFormat(s)) {\n        // set up language\n        config.language = Config.getLanguage(s.substring(9, s.length() - 1));\n        // set up tlp\n        s = input.readLine();\n        String tlpCanonicalName = s.substring(4);\n        try {\n          config.tlp = ReflectionLoading.loadByReflection(tlpCanonicalName);\n          log.info(\"Loaded TreebankLanguagePack: \" + tlpCanonicalName);\n        } catch (Exception e) {\n          log.warn(\"Error: Failed to load TreebankLanguagePack: \" + tlpCanonicalName);\n        }\n        s = input.readLine();\n      }\n      int nDict = Integer.parseInt(s.substring(s.indexOf('=') + 1));\n      s = input.readLine();\n      int nPOS = Integer.parseInt(s.substring(s.indexOf('=') + 1));\n      s = input.readLine();\n      int nLabel = Integer.parseInt(s.substring(s.indexOf('=') + 1));\n      s = input.readLine();\n      int eSize = Integer.parseInt(s.substring(s.indexOf('=') + 1));\n      s = input.readLine();\n      int hSize = Integer.parseInt(s.substring(s.indexOf('=') + 1));\n      s = input.readLine();\n      int nTokens = Integer.parseInt(s.substring(s.indexOf('=') + 1));\n      s = input.readLine();\n      int nPreComputed = Integer.parseInt(s.substring(s.indexOf('=') + 1));\n\n      knownWords = new ArrayList<>();","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/nndep/DependencyParser.java#L517-L553","documentation":"While reading a saved DependencyParser model file, CoreNLP instantiates the TreebankLanguagePack named in the model via reflection (ReflectionLoading.loadByReflection). If the class cannot be instantiated, the parser logs this warning and continues with config.tlp left unset (or its default), which can cause downstream failures or wrong preprocessing behavior.","triggerScenarios":"loadModelFile reads a 'tlp=' line from a serialized nndep model and tries Class.forName + newInstance on that class name; any exception (class not on classpath, wrong package after refactor, no no-arg constructor, class loading error) triggers the log.warn at line 535.","commonSituations":"Loading a model trained with a different language pack (e.g., a Chinese/English TLP) while running with only the core jar but not the models/classpath containing that TLP class; CoreNLP version upgrades that moved or renamed TLP classes; custom TLP not shipped with the deployment.","solutions":["Add the jar containing the named TreebankLanguagePack class (usually stanford-corenlp-x.x-models.jar or the language-specific model jar) to the classpath.","Check the exact fully-qualified TLP name stored in the model file and confirm the class exists in your CoreNLP version (class names moved between versions).","Re-train or regenerate the parser model with a TLP class available in your deployment.","If the default TLP is acceptable, set the tlp explicitly in the parser options so behavior is deterministic instead of relying on the failed reflection load."],"exampleFix":"// before (classpath missing the TLP class)\nDependencyParser model = DependencyParser.loadModel(\"edu/stanford/nlp/models/parser/nndep/english_UD.gz\");\n\n// after: ensure the models jar is on the classpath, e.g.\n// java -cp stanford-corenlp.jar:stanford-corenlp-models.jar:... YourMain\ndependencyParserOpts(\"-model\", \"edu/stanford/nlp/models/parser/nndep/english_UD.gz\",\n                     \"-tlp\", \"edu.stanford.nlp.trees.PennTreebankLanguagePack\");","handlingStrategy":"fallback","validationCode":"// Verify the TLP class loads before opening the model\ntry {\n  Class.forName(\"edu.stanford.nlp.trees.PennTreebankLanguagePack\");\n} catch (ClassNotFoundException e) {\n  throw new IllegalStateException(\"Required TreebankLanguagePack missing from classpath\", e);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship the corenlp models jar matching your library version on the classpath","After upgrading CoreNLP, grep model options for TLP class names and verify they still exist","Set the -tlp option explicitly so failures are deterministic and diagnosable","Keep custom TreebankLanguagePacks in a jar included in every deployment"],"tags":["nlp","reflection","classpath","model-loading"],"backgroundTag":"class-not-found","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"}