{"record":{"id":"5818881a173195a0","repo":"antlr/antlr4","slug":"rulename-cannot-be-null-or-empty-581888","errorCode":null,"errorMessage":"ruleName cannot be null or empty.","messagePattern":"ruleName cannot be null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/CSharp/src/Tree/Pattern/RuleTagToken.cs","lineNumber":92,"sourceCode":"        /// <param name=\"label\">\n        /// The label associated with the rule tag, or\n        /// <see langword=\"null\"/>\n        /// if\n        /// the rule tag is unlabeled.\n        /// </param>\n        /// <exception>\n        /// IllegalArgumentException\n        /// if\n        /// <paramref name=\"ruleName\"/>\n        /// is\n        /// <see langword=\"null\"/>\n        /// or empty.\n        /// </exception>\n        public RuleTagToken(string ruleName, int bypassTokenType, string label)\n        {\n            if (string.IsNullOrEmpty(ruleName))\n            {\n                throw new ArgumentException(\"ruleName cannot be null or empty.\");\n            }\n            this.ruleName = ruleName;\n            this.bypassTokenType = bypassTokenType;\n            this.label = label;\n        }\n\n        /// <summary>Gets the name of the rule associated with this rule tag.</summary>\n        /// <remarks>Gets the name of the rule associated with this rule tag.</remarks>\n        /// <returns>The name of the parser rule associated with this rule tag.</returns>\n        [NotNull]\n        public string RuleName\n        {\n            get\n            {\n                return ruleName;\n            }\n        }\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Tree/Pattern/RuleTagToken.cs#L74-L110","documentation":"RuleTagToken's constructor rejects a null or empty ruleName. RuleTagToken is the internal token the pattern matcher conjures for a rule tag like <expr>; it must carry the rule name so matching can compare it against real rule invocations. The check fires when the token is built with an empty rule name.","triggerScenarios":"Direct construction new RuleTagToken(\"\", bypassTokenType, label); via the matcher when a tag chunk somehow has an empty tag (normally TagChunk already rejects empty tags, so this is a defense-in-depth guard).","commonSituations":"Building custom pattern tokens by hand; string manipulation producing an empty tag between delimiters like '<>' combined with a bypassed TagChunk path; porting code between runtimes where an intermediate guard is missing.","solutions":["Pass the non-empty rule name exactly as declared in the grammar.","Ensure tag chunks are never constructed with empty tags — validate pattern strings for '<>' before compiling.","Prefer letting ParseTreePatternMatcher create RuleTagTokens via Compile instead of constructing them directly."],"exampleFix":"// before\nvar t = new RuleTagToken(ruleNameField /* maybe empty */, type, label);\n\n// after\nif (string.IsNullOrEmpty(ruleNameField)) throw new ArgumentException(nameof(ruleNameField));\nvar t = new RuleTagToken(ruleNameField, type, label);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(ruleName)) throw new ArgumentException(\"ruleName required\", nameof(ruleName));\nvar t = new RuleTagToken(ruleName, bypassTokenType, label);","typeGuard":"static bool IsValidRuleName(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":null,"preventionTips":["Let ParseTreePatternMatcher create RuleTagTokens via Compile rather than constructing them directly.","Reject empty tags ('<>') in pattern strings up front."],"tags":["antlr","csharp","rule-tag-token","null-check","pattern"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}