antlr/antlr4 · error · IllegalArgumentException

start cannot be null or empty

Error message

start cannot be null or empty

What it means

Error "start cannot be null or empty" thrown in antlr/antlr4.

Source

Thrown at runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java:137

	public ParseTreePatternMatcher(Lexer lexer, Parser parser) {
		this.lexer = lexer;
		this.parser = parser;
	}

	/**
	 * Set the delimiters used for marking rule and token tags within concrete
	 * syntax used by the tree pattern parser.
	 *
	 * @param start The start delimiter.
	 * @param stop The stop delimiter.
	 * @param escapeLeft The escape sequence to use for escaping a start or stop delimiter.
	 *
	 * @exception IllegalArgumentException if {@code start} is {@code null} or empty.
	 * @exception IllegalArgumentException if {@code stop} is {@code null} or empty.
	 */
	public void setDelimiters(String start, String stop, String escapeLeft) {
		if (start == null || start.isEmpty()) {
			throw new IllegalArgumentException("start cannot be null or empty");
		}

		if (stop == null || stop.isEmpty()) {
			throw new IllegalArgumentException("stop cannot be null or empty");
		}

		this.start = start;
		this.stop = stop;
		this.escape = escapeLeft;
	}

	/** Does {@code pattern} matched as rule {@code patternRuleIndex} match {@code tree}? */
	public boolean matches(ParseTree tree, String pattern, int patternRuleIndex) {
		ParseTreePattern p = compile(pattern, patternRuleIndex);
		return matches(tree, p);
	}

	/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Pass a non-null, non-empty start tag name to ParseTreePatternMatcher.setDelimiters(...).
  2. Choose delimiter characters that do not appear literally in your patterns.

Example fix

matcher.setDelimiters("<", ">", "$");

When it happens

Trigger: ParseTreePatternMatcher.setStart() called with null or empty string.

Common situations: Use a non-empty delimiter such as '<' for setStart; validate user-supplied delimiters before configuring the matcher.


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