stanfordnlp/CoreNLP · error · RuntimeException
Error -- attempted to conditionalize a GeneralizedCounter of
Error message
Error -- attempted to conditionalize a GeneralizedCounter of depth depth()
What it means
conditionalizeOnce(o) is shorthand for conditioning on a single top-level key, which requires the GeneralizedCounter to have at least depth 1... but the guard actually rejects depth() < 1 only for the check's phrasing while conditionalizeHelper requires depth > 1 to descend; the thrown RuntimeException reports the current depth(). In effect, calling it on a counter with no remaining levels to condition on fails.
Solutions
- Guard with if (gc.depth() > 1) before calling conditionalizeOnce, since a depth-1 counter cannot be conditioned further
- Track how many conditioning steps you have performed and stop at depth - 1 steps
- Use getCount() directly on shallow counters instead of conditioning
Example fix
// before
GeneralizedCounter<String> gc = ...;
gc = gc.conditionalizeOnce("a");
gc = gc.conditionalizeOnce("b"); // depth exhausted -> throws
// after
if (gc.depth() > 1) {
gc = gc.conditionalizeOnce("b");
} else {
double c = gc.getCount(Collections.singletonList("b"));
} Defensive patterns
Strategy: validation
Validate before calling
if (gc.depth() < 2) { // helper needs a level to descend into
throw new IllegalStateException("cannot conditionalizeOnce at depth " + gc.depth());
} Type guard
boolean canConditionOnce(GeneralizedCounter<?> gc) { return gc.depth() > 1; } Try / catch
try {
GeneralizedCounter<K> sub = gc.conditionalizeOnce(o);
} catch (RuntimeException e) {
if (e.getMessage().contains("attempted to conditionalize")) { /* stop conditioning; read leaf counts */ }
} Prevention
- Count conditioning steps and cap at depth - 1
- Check depth() > 1 before each conditionalizeOnce
- Prefer conditionalize(List) with a bounded context over ad-hoc repeated calls
When it happens
Trigger: Calling conditionalizeOnce(o) on a GeneralizedCounter whose depth() is too small to condition on a top-level key (depth reduced by prior conditionalize/conditionalizeOnce calls, or a leaf-level counter).
Common situations: Iterative smoothing/lookup code that repeatedly calls conditionalizeOnce without tracking remaining depth; passing a flattened (depth-1) counter where a hierarchical one was expected.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Error -- can't conditionalize a distribution of depth 1
- Error -- attempted to conditionalize a GeneralizedCounter of
- Must supply a target label to compute precision and recall a
- Cannot compute precision and recall on unlabelled dataset. O
- Line format error at line ${lineNo}: ${line}
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/66e75c8a89f92091.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/stats/GeneralizedCounter.java:425
int n = l.size();
if (n >= depth()) {
throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth() + " on a vector of length " + n);
} else {
GeneralizedCounter<K> next = this;
for (K o: l) {
next = next.conditionalizeHelper(o);
}
return next;
}
}
/**
* Returns a GeneralizedCounter conditioned on the given top level object.
* This is just shorthand (and more efficient) for <code>conditionalize(new Object[] { o })</code>.
*/
public GeneralizedCounter<K> conditionalizeOnce(K o) {
if (depth() < 1) {
throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth());
} else {
return conditionalizeHelper(o);
}
}
/**
* equivalent to incrementCount(l,o,1.0).
*/
public void incrementCount(List<K> l, K o) {
incrementCount(l, o, 1.0);
}
/**
* same as incrementCount(List, double) but as if Object o were at the end of the list
*/
public void incrementCount(List<K> l, K o, double count) {
if (l.size() != depth - 1) {
wrongDepth();View on GitHub (pinned to 1b7edd19c4)