{"record":{"id":"828a78d23db07493","repo":"stanfordnlp/CoreNLP","slug":"unknown-index-for-natural-logic-relation-inde","errorCode":null,"errorMessage":"Unknown index for Natural Logic relation: \" + index","messagePattern":"Unknown index for Natural Logic relation: \" \\+ index","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/naturalli/NaturalLogicRelation.java","lineNumber":82,"sourceCode":"\n  NaturalLogicRelation(int fixedIndex, boolean maintainsTruth, boolean negatesTruth, boolean maintainsFalsehood, boolean negatesFalsehood) {\n    this.fixedIndex = fixedIndex;\n    this.maintainsTruth = maintainsTruth;\n    this.negatesTruth = negatesTruth;\n    this.maintainsFalsehood = maintainsFalsehood;\n    this.negatesFalsehood = negatesFalsehood;\n  }\n\n  protected static NaturalLogicRelation byFixedIndex(int index) {\n    switch (index) {\n      case 0: return EQUIVALENT;\n      case 1: return FORWARD_ENTAILMENT;\n      case 2: return REVERSE_ENTAILMENT;\n      case 3: return NEGATION;\n      case 4: return ALTERNATION;\n      case 5: return COVER;\n      case 6: return INDEPENDENCE;\n      default: throw new IllegalArgumentException(\"Unknown index for Natural Logic relation: \" + index);\n    }\n  }\n\n  /**\n   * The MacCartney \"join table\" -- this determines the transitivity of entailment if we chain two relations together.\n   * These should already be projected up through the sentence, so that the relations being joined are relations between\n   * <i>sentences</i> rather than relations between <i>lexical items</i> (see {@link Polarity#projectLexicalRelation(NaturalLogicRelation)},\n   * set by {@link edu.stanford.nlp.naturalli.NaturalLogicAnnotator} using the {@link edu.stanford.nlp.naturalli.NaturalLogicAnnotations.PolarityAnnotation}).\n   * @param other The relation to join this relation with.\n   * @return The new joined relation.\n   */\n  public NaturalLogicRelation join(NaturalLogicRelation other) {\n    switch (this) {\n      case EQUIVALENT:\n        return other;\n      case FORWARD_ENTAILMENT:\n        switch (other) {\n          case EQUIVALENT:","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/naturalli/NaturalLogicRelation.java#L64-L100","documentation":"NaturalLogicRelation.byFixedIndex() maps integers 0-6 to the six natural logic relations plus equality; any other index has no corresponding relation, so an IllegalArgumentException is thrown. The index space is fixed by the enum's internal ordering.","triggerScenarios":"Calling byFixedIndex with an integer outside 0-6, e.g. a deserialized relation index from a corrupt/mismatched model file or an off-by-one when converting projective join table results.","commonSituations":"Persisting relation indices with one version of the library and reading them with another whose enum ordering changed; manual index arithmetic when composing relations.","solutions":["Validate the index is in [0,6] before calling byFixedIndex.","Prefer using the enum constants or NaturalLogicRelation.byName-ish lookups instead of raw indices.","If indices come from stored data, re-serialize them with the current library version and confirm the enum ordering."],"exampleFix":"// before\nNaturalLogicRelation rel = NaturalLogicRelation.byFixedIndex(idx);\n// after\nif (idx < 0 || idx > 6) throw new IllegalArgumentException(\"relation index out of range: \" + idx);\nNaturalLogicRelation rel = NaturalLogicRelation.byFixedIndex(idx);","handlingStrategy":"validation","validationCode":"if (index < 0 || index > 6) throw new IllegalArgumentException(\"Natural logic relation index must be 0-6: \" + index);","typeGuard":null,"tryCatchPattern":"try {\n  rel = NaturalLogicRelation.byFixedIndex(idx);\n} catch (IllegalArgumentException e) {\n  rel = NaturalLogicRelation.INDEPENDENCE; // or rethrow with context\n}","preventionTips":["Use enum constants, not raw ints, whenever possible","Store the library version alongside serialized relation indices","Range-check indices read from external files"],"tags":["index-out-of-range","naturalli","enum-value"],"backgroundTag":"value-out-of-range","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"}