{"record":{"id":"23537d3b5460303d","repo":"stanfordnlp/CoreNLP","slug":"not-a-valid-index-index","errorCode":null,"errorMessage":"Not a valid index: \" + index","messagePattern":"Not a valid index: \" \\+ index","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/naturalli/ClauseSplitter.java","lineNumber":63,"sourceCode":"    ClauseClassifierLabel(int val) {\n      this.index = (byte) val;\n    }\n    /** Seriously, why would Java not have this by default? */\n    @Override\n    public String toString() {\n      return this.name();\n    }\n    @SuppressWarnings(\"unused\")\n    public static ClauseClassifierLabel fromIndex(int index) {\n      switch (index) {\n        case 0:\n          return NOT_A_CLAUSE;\n        case 1:\n          return CLAUSE_INTERM;\n        case 2:\n          return CLAUSE_SPLIT;\n        default:\n          throw new IllegalArgumentException(\"Not a valid index: \" + index);\n      }\n    }\n  }\n\n\n  /**\n   * Train a clause searcher factory. That is, train a classifier for which arcs should be\n   * new clauses.\n   *\n   * @param trainingData The training data. This is a stream of triples of:\n   *                     <ol>\n   *                       <li>The sentence containing a known extraction.</li>\n   *                       <li>The span of the subject in the sentence, as a token span.</li>\n   *                       <li>The span of the object in the sentence, as a token span.</li>\n   *                     </ol>\n   * @param modelPath The path to save the model to. This is useful for {@link ClauseSplitter#load(String)}.\n   * @param trainingDataDump The path to save the training data, as a set of labeled featurized datums.\n   * @param featurizer The featurizer to use for this classifier.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/naturalli/ClauseSplitter.java#L45-L81","documentation":"ClauseSplitter.clauseClassifierLabelToValue / fromIndex maps small integer codes (0..2) to ClauseClassifierLabel enum values. Any index outside 0-2 has no label, so it throws IllegalArgumentException — a strict enum decode guard.","triggerScenarios":"Calling the fromIndex-style conversion with an integer other than 0, 1, or 2 — typically from a model file, annotation key, or serialized prediction containing an out-of-range code (e.g. -1 sentinel for missing labels).","commonSituations":"Model/annotation files saved with a different label vocabulary; code storing -1 as 'unknown' then feeding it to the converter; version drift between the classifier label set and the reader.","solutions":["Validate the index is in [0,2] before conversion and map out-of-range values to NOT_A_CLAUSE explicitly","Check the source of the integer (model output, annotation) for changed label semantics across versions","Regenerate any cached/persisted labels with the current library version"],"exampleFix":"// before\nClauseClassifierLabel label = ClauseSplitter.clauseClassifierLabelToValue(rawIndex);\n// after\nClauseClassifierLabel label = (rawIndex >= 0 && rawIndex <= 2)\n    ? ClauseSplitter.clauseClassifierLabelToValue(rawIndex)\n    : ClauseClassifierLabel.NOT_A_CLAUSE;","handlingStrategy":"type-guard","validationCode":"if (index < 0 || index > 2) { throw new IllegalArgumentException(\"Clause label index out of range: \" + index); }","typeGuard":"boolean isValidClauseLabelIndex(int i) { return i >= 0 && i <= 2; }","tryCatchPattern":"try { label = ClauseSplitter.clauseClassifierLabelToValue(idx); } catch (IllegalArgumentException e) { label = ClauseClassifierLabel.NOT_A_CLAUSE; }","preventionTips":["Clamp or map sentinel values like -1 before conversion","Regenerate persisted label codes after library upgrades","Document the valid label range at the API boundary"],"tags":["java","enum","naturalli","invalid-argument"],"backgroundTag":"invalid-enum-value","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"}