antlr/antlr4 · error · ArgumentException

start cannot be null or empty

Error message

start cannot be null or empty

What it means

ParseTreePatternMatcher.SetDelimiters rejects a null or empty start delimiter. The delimiters define how tags are recognized inside pattern strings (default '<' and '>'); an empty start delimiter would make tag scanning ambiguous or infinite, so it is rejected with ArgumentException.

Source

Thrown at runtime/CSharp/src/Tree/Pattern/ParseTreePatternMatcher.cs:218

        /// if
        /// <paramref name="start"/>
        /// is
        /// <see langword="null"/>
        /// or empty.
        /// </exception>
        /// <exception>
        /// IllegalArgumentException
        /// if
        /// <paramref name="stop"/>
        /// is
        /// <see langword="null"/>
        /// or empty.
        /// </exception>
        public virtual void SetDelimiters(string start, string stop, string escapeLeft)
        {
            if (string.IsNullOrEmpty(start))
            {
                throw new ArgumentException("start cannot be null or empty");
            }
            if (string.IsNullOrEmpty(stop))
            {
                throw new ArgumentException("stop cannot be null or empty");
            }
            this.start = start;
            this.stop = stop;
            this.escape = escapeLeft;
        }

        /// <summary>
        /// Does
        /// <paramref name="pattern"/>
        /// matched as rule
        /// <paramref name="patternRuleIndex"/>
        /// match
        /// <paramref name="tree"/>
        /// ?

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Supply a non-empty start delimiter string, e.g. SetDelimiters("[", "]", "\\").
  2. Validate configuration before calling SetDelimiters: fail with a clear config error naming the missing key.
  3. Do not call SetDelimiters at all if you want the default '<' and '>' delimiters.

Example fix

// before
matcher.SetDelimiters(cfg["tagStart"], cfg["tagStop"], "\\"); // tagStart missing -> null

// after
string start = cfg["tagStart"];
if (string.IsNullOrEmpty(start)) throw new ConfigException("tagStart not set");
matcher.SetDelimiters(start, cfg["tagStop"], "\\");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(start)) throw new ConfigurationErrorsException("pattern tag start delimiter is missing");
matcher.SetDelimiters(start, stop, escape);

Type guard

static bool IsValidDelimiter(string s) => !string.IsNullOrEmpty(s);

Prevention

When it happens

Trigger: Calling matcher.SetDelimiters("", "]", "\\") or SetDelimiters(null, ...) — typically when a configurable delimiter string comes from config and is missing.

Common situations: Making delimiters configurable via appsettings/environment and the key is absent; copying example code that passes an empty string as a placeholder; switching delimiter style (e.g. to '[' / ']') but forgetting to supply both values.

Related errors


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