antlr/antlr4 · error · ArgumentNullException

delegates

Error message

delegates

What it means

Error "delegates" thrown in antlr/antlr4.

Source

Thrown at runtime/CSharp/src/ProxyErrorListener.cs:26

namespace Antlr4.Runtime
{
    /// <summary>
    /// This implementation of
    /// <see cref="IAntlrErrorListener{Symbol}"/>
    /// dispatches all calls to a
    /// collection of delegate listeners. This reduces the effort required to support multiple
    /// listeners.
    /// </summary>
    /// <author>Sam Harwell</author>
    public class ProxyErrorListener<Symbol> : IAntlrErrorListener<Symbol>
    {
        private readonly IEnumerable<IAntlrErrorListener<Symbol>> delegates;

        public ProxyErrorListener(IEnumerable<IAntlrErrorListener<Symbol>> delegates)
        {
            if (delegates == null)
            {
                throw new ArgumentNullException("delegates");
            }
            this.delegates = delegates;
        }

        protected internal virtual IEnumerable<IAntlrErrorListener<Symbol>> Delegates
        {
            get
            {
                return delegates;
            }
        }

        public virtual void SyntaxError(TextWriter output, IRecognizer recognizer, Symbol offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
        {
            foreach (IAntlrErrorListener<Symbol> listener in delegates)
            {
                listener.SyntaxError(output, recognizer, offendingSymbol, line, charPositionInLine, msg, e);
            }

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Pass a non-null delegates array to the ProxyErrorListener constructor.
  2. If you have no listeners yet, use an empty array or add listeners via parser.AddErrorListener instead of a proxy.

Example fix

var proxy = new ProxyErrorListener(new IAntlrErrorListener<IToken>[] { myListener });

When it happens

Trigger: ProxyErrorListener constructed with a null delegates array or null delegate element.

Common situations: Pass non-null IAntlrErrorListener instances to the ProxyErrorListener constructor.


AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14). Data as JSON: /api/errors/442827b0c80ff1b3. Report an issue: GitHub.