antlr/antlr4 · critical · Error

ANTLR panic

Error message

ANTLR panic

What it means

Tool.panic() is the ANTLR tool's last-resort abort: it throws java.lang.Error('ANTLR panic') for unrecoverable internal failures. Error (not Exception) is deliberate so it bypasses normal catch blocks; in the tool it is typically reached via the ErrorManager after fatal error conditions.

Source

Thrown at tool/src/org/antlr/v4/Tool.java:967

		if ( listeners.isEmpty() ) {
			defaultListener.warning(msg);
		}
		else {
			for (ANTLRToolListener l : listeners) l.warning(msg);
		}

		if (warnings_are_errors) {
			errMgr.emit(ErrorType.WARNING_TREATED_AS_ERROR, new ANTLRMessage(ErrorType.WARNING_TREATED_AS_ERROR));
		}
	}

	public void version() {
		info("ANTLR Parser Generator  Version " + VERSION);
	}

	public void exit(int e) { System.exit(e); }

	public void panic() { throw new Error("ANTLR panic"); }

}

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Capture the tool output/errors immediately preceding the panic — the real cause is logged before it
  2. Reproduce with the same grammar on the latest ANTLR release; if it persists, report with a minimal grammar
  3. Do not catch Error in build scripts; fix the underlying fatal error instead
Defensive patterns

Strategy: try-catch

Try / catch

try { tool.processGrammars(args); } catch (Error e) { /* ANTLR panic: capture preceding tool output for root cause */ }

Prevention

When it happens

Trigger: Internal invariant violations during grammar compilation, or ErrorManager panic paths routing here; also user code calling tool.panic() directly.

Common situations: Corrupt/incompatible grammar metadata, severe tool bugs, or customized Tool subclasses that call panic(); sometimes surfaced when error limits (ERROR_MANAGER punishing fatal errors) are exceeded.

Related errors


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