{"record":{"id":"20d5d286d90075d0","repo":"stanfordnlp/CoreNLP","slug":"unhandled-natural-logic-relation-insertionrel","errorCode":null,"errorMessage":"Unhandled natural logic relation: \" + insertionRel","messagePattern":"Unhandled natural logic relation: \" \\+ insertionRel","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/naturalli/NaturalLogicRelation.java","lineNumber":602,"sourceCode":"      } else if (dependencyLabel.startsWith(\"advcl\")) {\n        return NaturalLogicRelation.REVERSE_ENTAILMENT;\n      } else {\n        return NaturalLogicRelation.INDEPENDENCE;\n      }\n    }\n  }\n\n  private static NaturalLogicRelation insertionToDeletion(NaturalLogicRelation insertionRel) {\n    switch (insertionRel) {\n      case EQUIVALENT: return EQUIVALENT;\n      case FORWARD_ENTAILMENT: return REVERSE_ENTAILMENT;\n      case REVERSE_ENTAILMENT: return FORWARD_ENTAILMENT;\n      case NEGATION: return NEGATION;\n      case ALTERNATION: return COVER;\n      case COVER: return ALTERNATION;\n      case INDEPENDENCE: return INDEPENDENCE;\n      default:\n        throw new IllegalStateException(\"Unhandled natural logic relation: \" + insertionRel);\n    }\n  }\n\n  /**\n   * Returns the natural logic relation corresponding to the given dependency arc being deleted from a sentence.\n   */\n  public static NaturalLogicRelation forDependencyDeletion(String dependencyLabel) {\n    return forDependencyDeletion(dependencyLabel, true);\n  }\n\n  /**\n   * Returns the natural logic relation corresponding to the given dependency arc being deleted from a sentence.\n   * @param dependencyLabel The label we are checking the relation for\n   * @param isSubject Whether this is on the subject side of a relation (e.g., for CONJ_OR edges)\n   */\n  public static NaturalLogicRelation forDependencyDeletion(String dependencyLabel, boolean isSubject) {\n    NaturalLogicRelation rel = forDependencyInsertion(dependencyLabel, isSubject);\n    return insertionToDeletion(rel);","sourceCodeStart":584,"sourceCodeEnd":620,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/naturalli/NaturalLogicRelation.java#L584-L620","documentation":"insertionToDeletion() maps an insertion relation to its dual deletion relation; the switch handles FORWARD/REVERSE_ENTAILMENT, NEGATION, ALTERNATION, COVER, and INDEPENDENCE. The default branch throws an IllegalStateException for any other relation, meaning an unexpected enum value (or null via switch on null) reached the method.","triggerScenarios":"Calling insertionToDeletion with null (default branch in a switch on null throws NPE in older style, or hits default semantics) or an unexpected relation constant, typically reached via forDependencyDeletion when a computed insertion relation is invalid.","commonSituations":"Modified enum constants in forks; passing a relation computed by buggy index conversion code.","solutions":["Ensure the relation passed in comes from the standard NaturalLogicRelation constants, not from manual index conversion.","Null-check the argument before calling to avoid falling into the default branch.","If you added enum constants, add matching cases in insertionToDeletion (and forDependencyDeletion)."],"exampleFix":"// before\nNaturalLogicRelation del = NaturalLogicRelation.insertionToDeletion(rel);\n// after\nif (rel != null) {\n  NaturalLogicRelation del = NaturalLogicRelation.insertionToDeletion(rel);\n}","handlingStrategy":"validation","validationCode":"if (insertionRel == null) throw new IllegalArgumentException(\"insertion relation required\");","typeGuard":null,"tryCatchPattern":"try {\n  del = NaturalLogicRelation.insertionToDeletion(rel);\n} catch (IllegalStateException e) {\n  log.warn(\"Unhandled relation \" + rel + \", defaulting to INDEPENDENCE\");\n  del = NaturalLogicRelation.INDEPENDENCE;\n}","preventionTips":["Derive relations only from NaturalLogicRelation constants","Null-check relations computed from index conversions","Keep enum constants and switch tables in sync when forking"],"tags":["unhandled-enum","naturalli","internal-invariant"],"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"}