{"record":{"id":"5623140879bb76d4","repo":"stanfordnlp/CoreNLP","slug":"error-unknown-dependency-type-dependencytype","errorCode":null,"errorMessage":"ERROR: unknown dependency type: ${dependencyType}","messagePattern":"ERROR: unknown dependency type: (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/machinereading/BasicRelationFeatureFactory.java","lineNumber":597,"sourceCode":"\n  protected void addDependencyPathFeatures(\n          Counter<String> features,\n          RelationMention rel,\n          EntityMention arg0,\n          EntityMention arg1,\n          List<String> types,\n          List<String> checklist,\n          Logger logger) {\n    SemanticGraph graph = null;\n    if(dependencyType == null) dependencyType = DEPENDENCY_TYPE.COLLAPSED_CCPROCESSED; // needed for backwards compatibility. old serialized models don't have it\n    if(dependencyType == DEPENDENCY_TYPE.COLLAPSED_CCPROCESSED)\n      graph = rel.getSentence().get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class);\n    else if(dependencyType == DEPENDENCY_TYPE.COLLAPSED)\n      graph = rel.getSentence().get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);\n    else if(dependencyType == DEPENDENCY_TYPE.BASIC)\n      graph = rel.getSentence().get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);\n    else\n      throw new RuntimeException(\"ERROR: unknown dependency type: \" + dependencyType);\n\n    if (graph == null) {\n      Tree tree = rel.getSentence().get(TreeAnnotation.class);\n      if(tree == null){\n        log.info(\"WARNING: found sentence without TreeAnnotation. Skipped dependency-path features.\");\n        return;\n      }\n      try {\n        graph = SemanticGraphFactory.makeFromTree(tree, Mode.COLLAPSED, GrammaticalStructure.Extras.NONE, null, true);\n\n      } catch(Exception e){\n        log.info(\"WARNING: failed to generate dependencies from tree \" + tree.toString());\n        e.printStackTrace();\n        log.info(\"Skipped dependency-path features.\");\n        return;\n      }\n    }\n","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/machinereading/BasicRelationFeatureFactory.java#L579-L615","documentation":"addDependencyPathFeatures selects a SemanticGraph annotation based on the configured dependencyType. The if/else-if chain only handles SEMANTIC (untyped/collapsed-ccprocessed), COLLAPSED, and BASIC; any other DEPENDENCY_TYPE value hits the else and throws RuntimeException. It is an internal enum-coverage failure, not user input directly.","triggerScenarios":"Invoking addFeatures with a feature set that includes dependency-path features and a DEPENDENCY_TYPE constant outside the three supported values (e.g. a newly added enum constant or an uninitialized/custom value).","commonSituations":"Extending DEPENDENCY_TYPE with new constants (e.g. ENHANCED) without updating this method; reflection/config code assigning an out-of-range value; merging code from different CoreNLP versions with divergent enums.","solutions":["Use one of the supported types: SEMANTIC (CollapsedCCProcessed), COLLAPSED, or BASIC.","Extend the if/else chain in addDependencyPathFeatures to handle any new DEPENDENCY_TYPE constant you added.","Replace the enum's unhandled values with a switch that throws at compile-checkable points or defaults to CollapsedCCProcessed.","Validate dependencyType early (constructor/init) so failures surface before per-sentence feature extraction."],"exampleFix":"// before\nelse\n  throw new RuntimeException(\"ERROR: unknown dependency type: \" + dependencyType);\n// after\nelse if(dependencyType == DEPENDENCY_TYPE.ENHANCED)\n  graph = rel.getSentence().get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);\nelse\n  throw new RuntimeException(\"ERROR: unknown dependency type: \" + dependencyType);","handlingStrategy":"validation","validationCode":"if (dependencyType != DEPENDENCY_TYPE.SEMANTIC\n    && dependencyType != DEPENDENCY_TYPE.COLLAPSED\n    && dependencyType != DEPENDENCY_TYPE.BASIC) {\n  throw new IllegalArgumentException(\"Unsupported dependencyType: \" + dependencyType);\n}","typeGuard":null,"tryCatchPattern":"try {\n  addDependencyPathFeatures(rel, sent, depType, features, domain);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"unknown dependency type\")) {\n    log.warning(\"Falling back to COLLAPSED dependency type\");\n    addDependencyPathFeatures(rel, sent, DEPENDENCY_TYPE.COLLAPSED, features, domain);\n    return;\n  }\n  throw e;\n}","preventionTips":["Only use the three supported DEPENDENCY_TYPE constants.","If adding new enum constants, update every if/else chain that dispatches on the enum.","Prefer exhaustive switch over enum so new constants break compilation instead of runtime."],"tags":["java","nlp","enum"],"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"}