{"record":{"id":"c8cb5b48f186e71f","repo":"antlr/antlr4","slug":"delegates-c8cb5b","errorCode":null,"errorMessage":"delegates","messagePattern":"delegates","errorType":"exception","errorClass":"ReferenceError","httpStatus":null,"severity":"error","filePath":"runtime/Python3/src/antlr4/error/ErrorListener.py","lineNumber":55,"sourceCode":"    # This implementation prints messages to {@link System#err} containing the\n    # values of {@code line}, {@code charPositionInLine}, and {@code msg} using\n    # the following format.</p>\n    #\n    # <pre>\n    # line <em>line</em>:<em>charPositionInLine</em> <em>msg</em>\n    # </pre>\n    #\n    def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):\n        print(\"line \" + str(line) + \":\" + str(column) + \" \" + msg, file=sys.stderr)\n\nConsoleErrorListener.INSTANCE = ConsoleErrorListener()\n\nclass ProxyErrorListener(ErrorListener):\n\n    def __init__(self, delegates):\n        super().__init__()\n        if delegates is None:\n            raise ReferenceError(\"delegates\")\n        self.delegates = delegates\n\n    def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):\n        for delegate in self.delegates:\n            delegate.syntaxError(recognizer, offendingSymbol, line, column, msg, e)\n\n    def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):\n        for delegate in self.delegates:\n            delegate.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs)\n\n    def reportAttemptingFullContext(self, recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs):\n        for delegate in self.delegates:\n            delegate.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs)\n\n    def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):\n        for delegate in self.delegates:\n            delegate.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs)\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/Python3/src/antlr4/error/ErrorListener.py#L37-L73","documentation":"ProxyErrorListener is a fan-out error listener: it forwards every callback (syntaxError, reportAmbiguity, ...) to each listener in the delegates list. Its constructor raises ReferenceError('delegates') when delegates is None, mirroring the Java runtime's NullPointerException message. It is a plain constructor-contract check, not a parse-time failure.","triggerScenarios":"ProxyErrorListener(None) or ProxyErrorListener(delegates) where delegates evaluated to None (e.g. a list built conditionally that ended up empty-None, or a typo'd variable).","commonSituations":"Custom multi-listener setups that aggregate console + logging listeners; passing a default argument that is None when no extra listeners were configured.","solutions":["Pass an iterable (possibly empty) list: ProxyErrorListener([]) is valid — only None is rejected.","Default the parameter safely: def make_listener(extra=None): return ProxyErrorListener(extra or [ConsoleErrorListener.INSTANCE])."],"exampleFix":"# before\nlistener = ProxyErrorListener(maybe_listeners)  # maybe_listeners is None -> ReferenceError\n\n# after\nlistener = ProxyErrorListener(maybe_listeners or [])","handlingStrategy":"validation","validationCode":"def proxy_listener(delegates=None):\n    return ProxyErrorListener(delegates if delegates else [])","typeGuard":"def make_proxy(delegates):\n    if delegates is None:\n        delegates = []\n    assert all(hasattr(d, 'syntaxError') for d in delegates)\n    return ProxyErrorListener(delegates)","tryCatchPattern":null,"preventionTips":["Pass an iterable (empty list is fine) — only None is rejected","Default parameters with `or []` when callers may omit the listener list"],"tags":["antlr4","python","error-listener","null-argument","validation"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}