antlr/antlr4 · error · MojoExecutionException
Fatal error occured while evaluating the names of the gramma
Error message
Fatal error occured while evaluating the names of the grammar files to analyze
What it means
matchImpl also requires a non-null patternTree — the compiled form of the pattern (tags resolved to TokenTagToken/RuleTagToken nodes). A null pattern tree means pattern compilation produced nothing, which indicates a bug in the compile path or bad arguments, and comparing against it is undefined; IllegalArgumentException fails fast.
Source
Thrown at antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java:271
outputDir.mkdirs();
}
GrammarDependencies dependencies = new GrammarDependencies(sourceDirectory, libDirectory, arguments, getDependenciesStatusFile(), getLog());
// Now pick up all the files and process them with the Tool
//
List<List<String>> argumentSets;
Set<File> grammarFiles;
Set<File> importGrammarFiles;
try {
List<String> args = getCommandArguments();
grammarFiles = getGrammarFiles(sourceDirectory);
importGrammarFiles = getImportFiles(sourceDirectory);
argumentSets = processGrammarFiles(args, grammarFiles, dependencies, sourceDirectory);
} catch (Exception e) {
log.error(e);
throw new MojoExecutionException("Fatal error occured while evaluating the names of the grammar files to analyze", e);
}
log.debug("Output directory base will be " + outputDirectory.getAbsolutePath());
log.info("ANTLR 4: Processing source directory " + sourceDirectory.getAbsolutePath());
for (List<String> args : argumentSets) {
try {
// Create an instance of the ANTLR 4 build tool
tool = new CustomTool(args.toArray(new String[0]));
} catch (Exception e) {
log.error("The attempt to create the ANTLR 4 build tool failed, see exception report for details", e);
throw new MojoFailureException("Error creating an instanceof the ANTLR tool.", e);
}
try {
dependencies.analyze(grammarFiles, importGrammarFiles, tool);
} catch (Exception e) {
log.error("Dependency analysis failed, see exception report for details",
e);View on GitHub (pinned to 7d5770395b)
Solutions
- Always pass pattern.getPatternTree() as patternTree — never build the call by hand with null.
- Prefer the public matches(tree, pattern, ruleIndex) / matches(tree, ParseTreePattern) entry points which compile correctly.
- Assert non-null pattern tree in test setup before invoking internals.
Example fix
// before
mismatch = matcher.matchImpl(tree, null, labels); // subclass experiment
// after
ParseTreePattern p = matcher.compile("<ID>", R.expr);
mismatch = matcher.matchImpl(tree, p.getPatternTree(), labels); Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(pattern, "compile the pattern first"); ParseTree patternTree = pattern.getPatternTree(); Objects.requireNonNull(patternTree, "pattern tree missing"); matcher.matchImpl(tree, patternTree, labels);
Prevention
- Use public entry points matches(...) instead of matchImpl.
- Always obtain patternTree from pattern.getPatternTree().
- Keep test doubles away from matcher internals.
When it happens
Trigger: Subclass or reflection calls to matchImpl with a null patternTree; constructing a mismatched invocation where the compiled ParseTreePattern's pattern tree was never obtained (e.g. passing null instead of pattern.getPatternTree()).
Common situations: Extending ParseTreePatternMatcher and hand-calling matchImpl; tests exercising the matcher internals with placeholder nulls.
Related errors
- missing interface implementation
- cannot consume EOF
- index cannot be negative
- Error creating an instanceof the ANTLR tool.
- Dependency analysis failed.
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/7925506f179de364.
Report an issue: GitHub.