antlr/antlr4 · error · RuntimeException
set is empty
Error message
set is empty
What it means
Error "set is empty" thrown in antlr/antlr4.
Source
Thrown at runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java:421
}
return false;
}
/** {@inheritDoc} */
@Override
public boolean isNil() {
return intervals==null || intervals.isEmpty();
}
/**
* Returns the maximum value contained in the set if not isNil().
*
* @return the maximum value contained in the set.
* @throws RuntimeException if set is empty
*/
public int getMaxElement() {
if ( isNil() ) {
throw new RuntimeException("set is empty");
}
Interval last = intervals.get(intervals.size()-1);
return last.b;
}
/**
* Returns the minimum value contained in the set if not isNil().
*
* @return the minimum value contained in the set.
* @throws RuntimeException if set is empty
*/
public int getMinElement() {
if ( isNil() ) {
throw new RuntimeException("set is empty");
}
return intervals.get(0).a;
}View on GitHub (pinned to 7d5770395b)
Solutions
- Call size() (or isEmpty()) before calling getMin() so you never read the minimum of an empty set.
- Guard the call: if (!set.isEmpty()) { Interval min = set.getMin(); }.
- If the set may legitimately be empty, handle that branch explicitly instead of asking for its minimum.
Example fix
IntervalSet set = new IntervalSet();
if (set.isEmpty()) {
// handle empty case, e.g. skip or use a default
} else {
Interval min = set.getMin();
} When it happens
Trigger: Thrown by IntervalSet.minElement()/maxElement() when the set contains no intervals.
Common situations: Check set.isNil()/size>0 before calling minElement or maxElement; guard against empty IntervalSet after filtering or subtraction operations.
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/dbc2e92a67072830.
Report an issue: GitHub.