stanfordnlp/CoreNLP · error · IllegalStateException
Either logic is broken or Gabor can't code.
Error message
Either logic is broken or Gabor can't code.
What it means
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.
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
Example fix
// before Span s = Util.tokensToSpan(badTokens); // after boolean ok = badTokens.stream().allMatch(t -> t.index() >= 1); Span s = ok ? Util.tokensToSpan(badTokens) : null;
Defensive patterns
Strategy: type-guard
Validate before calling
long count = tokens.stream().mapToInt(HasIndex::index).distinct().count(); if (tokens.isEmpty() || count == 0) return null;
Type guard
boolean saneIndices(List<? extends HasIndex> toks) { return toks.stream().allMatch(t -> t.index() >= 1 && t.index() < 100000); } Try / catch
try { return Util.tokensToSpan(tokens); } catch (IllegalStateException e) { return null; /* log as bug */ } Prevention
- Use standard CoreLabel tokens with 1-based sequential indices
- Treat this exception as an invariant violation and log for debugging
When it happens
Trigger: 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.
Common situations: Custom HasIndex implementations returning pathological values; patched versions of the method; essentially never in normal use.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- oldTag starts with B, entity at position should not be null
- Unknown minimizer
- node cliqueFeatures[n]=
- edge cliqueFeatures[n]=
- : Inconsistent u2b/b2u arrays.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6eaa05429e8766f7.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/naturalli/Util.java:627
}});
/**
* Construct the spanning span of the given list of tokens.
*
* @param tokens The tokens that should define the span.
* @return A span (0-indexed) that covers all of the tokens.
*/
public static Span tokensToSpan(List<? extends HasIndex> tokens) {
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for (HasIndex token : tokens) {
min = Math.min(token.index() - 1, min);
max = Math.max(token.index(), max);
}
if (min < 0 || max == Integer.MAX_VALUE) {
throw new IllegalArgumentException("Could not compute span from tokens!");
} else if (min >= max) {
throw new IllegalStateException("Either logic is broken or Gabor can't code.");
} else {
return new Span(min, max);
}
}
}
View on GitHub (pinned to 1b7edd19c4)