{"record":{"id":"518e0454bcef677d","repo":"antlr/antlr4","slug":"tag-cannot-be-null-or-empty-518e04","errorCode":null,"errorMessage":"tag cannot be null or empty","messagePattern":"tag cannot be null or empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"runtime/CSharp/src/Tree/Pattern/TagChunk.cs","lineNumber":111,"sourceCode":"        /// </param>\n        /// <param name=\"tag\">\n        /// The tag, which should be the name of a parser rule or token\n        /// type.\n        /// </param>\n        /// <exception>\n        /// IllegalArgumentException\n        /// if\n        /// <paramref name=\"tag\"/>\n        /// is\n        /// <see langword=\"null\"/>\n        /// or\n        /// empty.\n        /// </exception>\n        public TagChunk(string label, string tag)\n        {\n            if (string.IsNullOrEmpty(tag))\n            {\n                throw new ArgumentException(\"tag cannot be null or empty\");\n            }\n            this.label = label;\n            this.tag = tag;\n        }\n\n        /// <summary>Get the tag for this chunk.</summary>\n        /// <remarks>Get the tag for this chunk.</remarks>\n        /// <returns>The tag for the chunk.</returns>\n        [NotNull]\n        public string Tag\n        {\n            get\n            {\n                return tag;\n            }\n        }\n\n        /// <summary>Get the label, if any, assigned to this chunk.</summary>","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Tree/Pattern/TagChunk.cs#L93-L129","documentation":"TagChunk's constructor rejects a null or empty tag. A TagChunk is one parsed piece of a pattern — either a tag (<ID>, <expr>, <label:tag>) or text. A tag chunk without a tag name carries no information and would break matching, so it is rejected. The label part may be null; only the tag is validated.","triggerScenarios":"Direct construction new TagChunk(\"label\", \"\") or new TagChunk(null, null); a pattern containing an empty tag '<>' reaching chunk construction.","commonSituations":"Programmatically assembling TagChunks from variables; empty tag '<>' in a user-supplied pattern (usually caught earlier by delimiter checks); refactoring pattern-building helpers that drop the tag argument.","solutions":["Always supply the tag name: new TagChunk(\"label\", \"ID\") or new TagChunk(null, \"expr\").","Validate pattern strings reject '<>' before they are chunked.","Add unit tests over your pattern-builder helpers asserting tags are non-empty."],"exampleFix":"// before\nchunks.Add(new TagChunk(label, tag)); // tag can be \"\"\n\n// after\nif (string.IsNullOrEmpty(tag)) throw new ArgumentException(\"tag required\", nameof(tag));\nchunks.Add(new TagChunk(label, tag));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(tag)) throw new ArgumentException(\"tag required\", nameof(tag));\nchunks.Add(new TagChunk(label, tag));","typeGuard":"static bool IsValidTag(string tag) => !string.IsNullOrEmpty(tag);","tryCatchPattern":null,"preventionTips":["Validate tag strings at the boundary where patterns or chunks are built.","Remember only the tag is validated; the label may be null."],"tags":["antlr","csharp","tag-chunk","null-check","pattern"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}