{"record":{"id":"dbc2e92a67072830","repo":"antlr/antlr4","slug":"set-is-empty","errorCode":null,"errorMessage":"set is empty","messagePattern":"set is empty","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java","lineNumber":421,"sourceCode":"\t\t}\n\t\treturn false;\n    }\n\n    /** {@inheritDoc} */\n    @Override\n    public boolean isNil() {\n        return intervals==null || intervals.isEmpty();\n    }\n\n\t/**\n\t * Returns the maximum value contained in the set if not isNil().\n\t *\n\t * @return the maximum value contained in the set.\n\t * @throws RuntimeException if set is empty\n\t */\n\tpublic int getMaxElement() {\n\t\tif ( isNil() ) {\n\t\t\tthrow new RuntimeException(\"set is empty\");\n\t\t}\n\t\tInterval last = intervals.get(intervals.size()-1);\n\t\treturn last.b;\n\t}\n\n\t/**\n\t * Returns the minimum value contained in the set if not isNil().\n\t *\n\t * @return the minimum value contained in the set.\n\t * @throws RuntimeException if set is empty\n\t */\n\tpublic int getMinElement() {\n\t\tif ( isNil() ) {\n\t\t\tthrow new RuntimeException(\"set is empty\");\n\t\t}\n\n\t\treturn intervals.get(0).a;\n\t}","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java#L403-L439","documentation":"Error \"set is empty\" thrown in antlr/antlr4.","triggerScenarios":"Thrown by IntervalSet.minElement()/maxElement() when the set contains no intervals.","commonSituations":"Check set.isNil()/size>0 before calling minElement or maxElement; guard against empty IntervalSet after filtering or subtraction operations.","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."],"exampleFix":"IntervalSet set = new IntervalSet();\nif (set.isEmpty()) {\n    // handle empty case, e.g. skip or use a default\n} else {\n    Interval min = set.getMin();\n}","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}