{"record":{"id":"71424b2bb8e2afcd","repo":"stanfordnlp/CoreNLP","slug":"label-argument-lacks-indexannotation","errorCode":null,"errorMessage":"Label argument lacks IndexAnnotation.","messagePattern":"Label argument lacks IndexAnnotation\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/UnnamedConcreteDependency.java","lineNumber":47,"sourceCode":"\n    headIndex = regentIndex;\n    depIndex = dependentIndex;\n  }\n  \n  public UnnamedConcreteDependency(Label regent, int regentIndex, Label dependent, int dependentIndex) {\n    super(regent, dependent);\n    \n    headIndex = regentIndex;\n    depIndex = dependentIndex;\n  }\n\n  public UnnamedConcreteDependency(Label regent, Label dependent) {\n    super(regent, dependent);\n\n    if (governor() instanceof HasIndex) {\n      headIndex = ((HasIndex) governor()).index();\n    } else {\n      throw new IllegalArgumentException(\"Label argument lacks IndexAnnotation.\");\n    }\n    if (dependent() instanceof HasIndex) {\n      depIndex = ((HasIndex) dependent()).index();\n    } else {\n      throw new IllegalArgumentException(\"Label argument lacks IndexAnnotation.\");\n    }\n  }\n  \n  public int getGovernorIndex() { return headIndex; }\n  \n  public int getDependentIndex() { return depIndex; }\n  \n  @Override\n  public int hashCode() {\n    return headIndex * (depIndex << 16);\n  }\n\n  @Override","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/UnnamedConcreteDependency.java#L29-L65","documentation":"UnnamedConcreteDependency stores integer head indexes from its labels; it requires the governor (regent) label to implement HasIndex so index() can be read. If the regent label lacks IndexAnnotation (does not implement HasIndex), the constructor throws IllegalArgumentException.","triggerScenarios":"Constructing new UnnamedConcreteDependency(regent, dependent) where the regent Label is a plain StringLabel/Word (no index annotation) instead of a CoreLabel or other HasIndex implementation.","commonSituations":"Creating dependencies from trees parsed with default factories that don't attach index annotations; forgetting to run indexing (e.g. via setSentIndex/word indexing) before building dependency objects.","solutions":["Use labels implementing HasIndex (CoreLabel with index set) for both regent and dependent","Set the index on labels before constructing the dependency ((HasIndex) label).setIndex(i))","Fall back to UnnamedDependency if you don't need index information"],"exampleFix":"// before\nnew UnnamedConcreteDependency(new StringLabel(\"ate\"), new StringLabel(\"dog\"));\n// after\nCoreLabel gov = new CoreLabel(); gov.setWord(\"ate\"); gov.setIndex(2);\nCoreLabel dep = new CoreLabel(); dep.setWord(\"dog\"); dep.setIndex(3);\nnew UnnamedConcreteDependency(gov, dep);","handlingStrategy":"type-guard","validationCode":"if (!(regent instanceof HasIndex) || !(((HasIndex) regent).index() >= 0)) {\n  throw new IllegalArgumentException(\"regent lacks index annotation\");\n}","typeGuard":"boolean isIndexedLabel(Label l) {\n  return l instanceof HasIndex && ((HasIndex) l).index() >= 0;\n}","tryCatchPattern":"try {\n  dep = new UnnamedConcreteDependency(regent, dependent);\n} catch (IllegalArgumentException e) {\n  dep = new UnnamedDependency(regent, dependent); // fallback without indexes\n}","preventionTips":["Index words (CoreLabel.setIndex) before building dependencies","Prefer CoreLabel for dependency endpoints","Validate HasIndex on both endpoints in tests"],"tags":["java","dependencies","labels"],"backgroundTag":"type-mismatch","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"}