{"record":{"id":"aff2a2923b652721","repo":"antlr/antlr4","slug":"parametername","errorCode":null,"errorMessage":"{parameterName}","messagePattern":"\\{parameterName\\}","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"runtime/CSharp/src/Misc/Args.cs","lineNumber":23,"sourceCode":"using System;\n\nnamespace Antlr4.Runtime.Misc\n{\n    /// <author>Sam Harwell</author>\n    public static class Args\n    {\n        /// <exception cref=\"System.ArgumentNullException\">\n        /// if\n        /// <paramref name=\"value\"/>\n        /// is\n        /// <see langword=\"null\"/>\n        /// .\n        /// </exception>\n        public static void NotNull(string parameterName, object value)\n        {\n            if (value == null)\n            {\n                throw new ArgumentNullException(parameterName);\n            }\n        }\n    }\n}\n","sourceCodeStart":5,"sourceCodeEnd":28,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Misc/Args.cs#L5-L28","documentation":"Misc.Args.NotNull(parameterName, value) is the runtime's central null-argument guard, used by many public APIs (recognizers, simulators, ATN deserializer, interpreters). It throws ArgumentNullException whose message is just the parameter name passed in — so the 'error message' you see is a parameter name like 'atn', 'input', or 'decisionState', not a sentence. This is a fail-fast contract check: the called API cannot do anything sensible with a null argument.","triggerScenarios":"Passing null to any runtime API guarded by Args.NotNull — typical call sites include setting a null ATN/deserializer on a simulator, constructing ParserInterpreter with null rule names or ATN, and recognizer Reset/Process calls with null streams. The parameter name in the exception message tells you which argument was null.","commonSituations":"DI containers resolving an optional dependency (vocabulary, error listener) to null; optional parameters defaulted to null then forwarded into runtime APIs; partial construction where a field is still null when the runtime API is invoked.","solutions":["Read the exception message: it names the exact parameter that was null (e.g. 'atn', 'input') — fix the corresponding argument at the call site","Coalesce nullable inputs before calling the runtime API (value ?? fallback or throw your own descriptive exception)","Register/initialize every dependency (streams, vocabularies, listeners) before constructing runtime objects"],"exampleFix":"// before\nvar interp = new ParserInterpreter(grammarFileName, vocabulary, null /*ruleNames*/, atn, input);\n// -> ArgumentNullException with message \"ruleNames\"\n\n// after\nvar interp = new ParserInterpreter(grammarFileName, vocabulary, ruleNames ?? Array.Empty<string>(), atn, input);","handlingStrategy":"validation","validationCode":"// The ArgumentNullException message names the null parameter; pre-validate each argument\nArgs.NotNull(nameof(atn), atn);\nArgs.NotNull(nameof(input), input);","typeGuard":null,"tryCatchPattern":"try { CallRuntimeApi(a, b, c); } catch (ArgumentNullException ane) { LogMissingDependency(ane.ParamName); throw; }","preventionTips":["Enable nullable reference types (nullable) so the compiler flags null forwarding into runtime APIs","Check the ParamName/message of ArgumentNullException — it names the exact argument to fix","Register all dependencies (streams, vocabularies, listeners) before constructing runtime objects"],"tags":["antlr","csharp","null-check","guard","api-contract"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}