{"record":{"id":"2f4a3f6ec1792ff6","repo":"antlr/antlr4","slug":"antlr-4-caught-build-errors","errorCode":null,"errorMessage":"ANTLR 4 caught {} build errors.","messagePattern":"ANTLR 4 caught (.+?) build errors\\.","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java","lineNumber":301,"sourceCode":"\t\t\t}\n\n            try {\n                dependencies.analyze(grammarFiles, importGrammarFiles, tool);\n            } catch (Exception e) {\n                log.error(\"Dependency analysis failed, see exception report for details\",\n                    e);\n                throw new MojoFailureException(\"Dependency analysis failed.\", e);\n            }\n\n\t\t\t// Set working directory for ANTLR to be the base source directory\n\t\t\ttool.inputDirectory = sourceDirectory;\n\n\t\t\ttool.processGrammarsOnCommandLine();\n\n\t\t\t// If any of the grammar files caused errors but did nto throw exceptions\n\t\t\t// then we should have accumulated errors in the counts\n\t\t\tif (tool.getNumErrors() > 0) {\n\t\t\t\tthrow new MojoExecutionException(\"ANTLR 4 caught \" + tool.getNumErrors() + \" build errors.\");\n\t\t\t}\n\t\t}\n\n        if (project != null) {\n            // Tell Maven that there are some new source files underneath the output directory.\n            addSourceRoot(this.getOutputDirectory());\n        }\n\n        try {\n            dependencies.save();\n        } catch (IOException ex) {\n            log.warn(\"Could not save grammar dependency status\", ex);\n        }\n    }\n\n\tprivate List<String> getCommandArguments() {\n\t\tList<String> args = new ArrayList<String>();\n","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java#L283-L319","documentation":"During pattern compilation a tag whose first character is neither uppercase (token convention) nor lowercase (rule convention) — for example a digit or punctuation — cannot be classified, so the matcher throws IllegalArgumentException 'invalid tag'. Tag content must start with an ASCII letter to be resolvable against the grammar.","triggerScenarios":"Patterns containing tags like <9id>, <_foo>, or non-ASCII leading characters; also tags that degenerate to empty after delimiter changes (e.g. setDelimiters misconfiguration making the tag body start at a non-letter).","commonSituations":"User-supplied pattern strings from a DSL or REPL; delimiters customized such that the extracted tag text starts with a symbol; generating patterns programmatically without validating tag names.","solutions":["Make every tag start with an ASCII letter (uppercase = token, lowercase = rule).","Validate pattern tags against ^[A-Za-z][A-Za-z0-9_]*$ before passing user input to compile().","If you intended literal text, do not wrap it in tag delimiters."],"exampleFix":"// before\nParseTreePattern p = m.compile(\"<1stArg> = <ID>\", R.assign);\n\n// after\nParseTreePattern p = m.compile(\"<firstArg> = <ID>\", R.assign);","handlingStrategy":"validation","validationCode":"private static final Pattern TAG = Pattern.compile(\"^[A-Za-z][A-Za-z0-9_]*$\");\nboolean tagOk(String tag) { return TAG.matcher(tag).matches(); }\n// validate before compile\nfor (String tag : extractTags(patternText)) {\n    if (!tagOk(tag)) throw new IllegalArgumentException(\"bad tag: \" + tag);\n}","typeGuard":"boolean isValidTagStart(char c) { return Character.isLetter(c); }","tryCatchPattern":"try {\n    pattern = matcher.compile(userPattern, ruleIndex);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"invalid tag\")) {\n        showTagSyntaxHelp(userPattern);\n    }\n    throw e;\n}","preventionTips":["Require tags to start with an ASCII letter (upper = token, lower = rule).","Validate user-supplied patterns before compiling.","Do not wrap literal text in tag delimiters."],"tags":["antlr","java","parse-tree-pattern","pattern-compile","validation"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}