{"record":{"id":"2360208367901e39","repo":"stanfordnlp/CoreNLP","slug":"mapdependencies-need-headfinder","errorCode":null,"errorMessage":"mapDependencies: need HeadFinder","messagePattern":"mapDependencies: need HeadFinder","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/Tree.java","lineNumber":1374,"sourceCode":"\n  /**\n   * Return a set of Label-Label dependencies, represented as\n   * Dependency objects, for the Tree.  The Labels are the ones of the leaf\n   * nodes of the tree, without mucking with them.\n   *\n   * @param f  Dependencies are excluded for which the Dependency is not\n   *           accepted by the Filter\n   * @param hf The HeadFinder to use to identify the head of constituents.\n   *           The code assumes\n   *           that it can use {@code headPreTerminal(hf)} to find a\n   *           tag and word to make a CoreLabel.\n   * @return Set of dependencies (each a {@code Dependency} between two\n   *           {@code CoreLabel}s, which each contain a tag(), word(),\n   *           and value(), the last two of which are identical).\n   */\n  public Set<Dependency<Label, Label, Object>> mapDependencies(Predicate<Dependency<Label, Label, Object>> f, HeadFinder hf) {\n    if (hf == null) {\n      throw new IllegalArgumentException(\"mapDependencies: need HeadFinder\");\n    }\n    Set<Dependency<Label, Label, Object>> deps = Generics.newHashSet();\n    for (Tree node : this) {\n      if (node.isLeaf() || node.children().length < 2) {\n        continue;\n      }\n      // Label l = node.label();\n      // log.info(\"doing kids of label: \" + l);\n      //Tree hwt = node.headPreTerminal(hf);\n      Tree hwt = node.headTerminal(hf);\n      // log.info(\"have hf, found head preterm: \" + hwt);\n      if (hwt == null) {\n        throw new IllegalStateException(\"mapDependencies: HeadFinder failed!\");\n      }\n\n      for (Tree child : node.children()) {\n        // Label dl = child.label();\n        // Tree dwt = child.headPreTerminal(hf);","sourceCodeStart":1356,"sourceCodeEnd":1392,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/Tree.java#L1356-L1392","documentation":"mapDependencies() requires a HeadFinder to compute which child of each node is the head when building dependencies. Passing null is rejected immediately with this IllegalArgumentException rather than failing later deep in the traversal.","triggerScenarios":"Calling tree.mapDependencies(f, null) — e.g. the HeadFinder variable was never initialized, or a helper method returned null and the result was passed straight through.","commonSituations":"Refactoring code where the HeadFinder used to be a field that is now null; conditionally constructing a HeadFinder that ends up unset; copy-pasted call sites where the hf argument was dropped.","solutions":["Pass a concrete HeadFinder instance, e.g. new CollinsHeadFinder() or UniversalSemanticHeadFinder","Null-check or assert the HeadFinder before calling mapDependencies","Trace where the null comes from (a factory/config lookup returning null) and fix the initialization"],"exampleFix":"// before\nSet<Dependency<Label,Label,Object>> deps = tree.mapDependencies(f, hf); // hf == null\n// after\nHeadFinder hf = new UniversalSemanticHeadFinder();\nSet<Dependency<Label,Label,Object>> deps = tree.mapDependencies(f, hf);","handlingStrategy":"type-guard","validationCode":"Objects.requireNonNull(hf, \"mapDependencies requires a HeadFinder\");","typeGuard":"boolean hasHeadFinder(HeadFinder hf) { return hf != null; }","tryCatchPattern":"try { deps = tree.mapDependencies(f, hf); } catch (IllegalArgumentException e) { log.error(\"Missing HeadFinder: {}\", e.getMessage()); }","preventionTips":["Initialize HeadFinder as a final field or constructor parameter","Null-check dependencies returned from factories before use","Prefer UniversalSemanticHeadFinder as a safe default"],"tags":["nlp","dependencies","null-argument"],"backgroundTag":"null-argument","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"}