{"record":{"id":"6eaa05429e8766f7","repo":"stanfordnlp/CoreNLP","slug":"either-logic-is-broken-or-gabor-can-t-code","errorCode":null,"errorMessage":"Either logic is broken or Gabor can't code.","messagePattern":"Either logic is broken or Gabor can't code\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/naturalli/Util.java","lineNumber":627,"sourceCode":"  }});\n\n  /**\n   * Construct the spanning span of the given list of tokens.\n   *\n   * @param tokens The tokens that should define the span.\n   * @return A span (0-indexed) that covers all of the tokens.\n   */\n  public static Span tokensToSpan(List<? extends HasIndex> tokens) {\n    int min = Integer.MAX_VALUE;\n    int max = Integer.MIN_VALUE;\n    for (HasIndex token : tokens) {\n      min = Math.min(token.index() - 1, min);\n      max = Math.max(token.index(), max);\n    }\n    if (min < 0 || max == Integer.MAX_VALUE) {\n      throw new IllegalArgumentException(\"Could not compute span from tokens!\");\n    } else if (min >= max) {\n      throw new IllegalStateException(\"Either logic is broken or Gabor can't code.\");\n    } else {\n      return new Span(min, max);\n    }\n  }\n}\n","sourceCodeStart":609,"sourceCodeEnd":633,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/naturalli/Util.java#L609-L633","documentation":"After computing min/max in Util.tokensToSpan, if min >= max (a zero-width or inverted span) the code throws IllegalStateException with the tongue-in-cheek message \"Either logic is broken or Gabor can't code.\" Given the loop, min = index-1 and max = index for the same token, so this should be impossible and signals corrupted token indices or a logic bug.","triggerScenarios":"Calling Util.tokensToSpan with tokens whose indices are inconsistent such that the computed min >= max — realistically only via integer overflow, corrupt token indices, or a modified implementation of the loop.","commonSituations":"Custom HasIndex implementations returning pathological values; patched versions of the method; essentially never in normal use.","solutions":["Verify token indices are sane (1-based, sequential) before calling tokensToSpan","Check for custom HasIndex implementations with incorrect index() behavior","Report as a bug with the token indices if reproducible"],"exampleFix":"// before\nSpan s = Util.tokensToSpan(badTokens);\n// after\nboolean ok = badTokens.stream().allMatch(t -> t.index() >= 1);\nSpan s = ok ? Util.tokensToSpan(badTokens) : null;","handlingStrategy":"type-guard","validationCode":"long count = tokens.stream().mapToInt(HasIndex::index).distinct().count();\nif (tokens.isEmpty() || count == 0) return null;","typeGuard":"boolean saneIndices(List<? extends HasIndex> toks) { return toks.stream().allMatch(t -> t.index() >= 1 && t.index() < 100000); }","tryCatchPattern":"try { return Util.tokensToSpan(tokens); } catch (IllegalStateException e) { return null; /* log as bug */ }","preventionTips":["Use standard CoreLabel tokens with 1-based sequential indices","Treat this exception as an invariant violation and log for debugging"],"tags":["java","illegal-state","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}