stanfordnlp/CoreNLP · error · RuntimeException
This point should never be reached
Error message
This point should never be reached
What it means
drawSample walks the cumulative distribution and returns the first object where the running sum reaches the random draw r; if the loop finishes without the sum reaching r, the code throws, indicating the parameter distribution did not sum to at least r (in practice an invariant violation: counts not normalized or corrupted).
Solutions
- Construct Multinomial only via the normalizing constructor and avoid mutating its internal parameters
- If you build parameters manually, normalize so the counts sum to 1.0 before sampling
- Catch the exception and retry the draw as a defensive fallback in sampling code
Example fix
// before
E sample = multinomial.drawSample(random);
// after
E sample;
try {
sample = multinomial.drawSample(random);
} catch (RuntimeException e) {
sample = null; // distribution not normalized; rebuild the Multinomial
} Defensive patterns
Strategy: try-catch
Validate before calling
double total = m.getParameters().totalCount();
if (Math.abs(total - 1.0) > 1e-6) throw new IllegalStateException("multinomial not normalized: " + total); Type guard
boolean isNormalized(Multinomial<?> m) { return Math.abs(m.getParameters().totalCount() - 1.0) < 1e-6; } Try / catch
try {
return m.drawSample(random);
} catch (RuntimeException e) {
if ("This point should never be reached".equals(e.getMessage())) {
return lastKeyAsFallback(m); // or rebuild the multinomial
}
throw e;
} Prevention
- Never mutate a Multinomial's parameters after construction
- Always build via the normalizing constructor
- Avoid deserializing multinomials across incompatible versions
When it happens
Trigger: Calling drawSample(Random) when the internal parameters do not sum to ~1.0 (e.g. the Multinomial was deserialized from an old version, or parameters were mutated); floating-point round-off in extreme cases where cumulative sum stays just below r near 1.0.
Common situations: Serialization/version drift leaving parameters unnormalized; manual edits to the parameters counter; sampling loops that repeatedly draw near 1.0 with under-normalized distributions.
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
- Tried to compare two Distribution
- oldTag starts with B, entity at position should not be null
- 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/460bc397932e7838.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/stats/Multinomial.java:65
}
public double logProbabilityOf(E object) {
if (!parameters.keySet().contains(object)) {
throw new RuntimeException("Not a valid object for this multinomial!");
}
return Math.log(parameters.getCount(object));
}
public E drawSample(Random random) {
double r = random.nextDouble();
double sum = 0.0;
for (E object : parameters.keySet()) {
sum += parameters.getCount(object);
if (sum >= r) {
return object;
}
}
throw new RuntimeException("This point should never be reached");
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
if (!(o instanceof Multinomial)) { return false; }
Multinomial otherMultinomial = (Multinomial)o;
return parameters.equals(otherMultinomial.parameters);
}
private int hashCode = -1;
@Override
public int hashCode() {
if (hashCode == -1) {
hashCode = parameters.hashCode() + 17;
}
return hashCode;
}View on GitHub (pinned to 1b7edd19c4)