{"record":{"id":"739ab55ee335b773","repo":"microsoft/aspire","slug":"must-not-be-null","errorCode":null,"errorMessage":"Must not be null","messagePattern":"Must not be null","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs","lineNumber":66,"sourceCode":"namespace OpenTelemetry.Internal\n{\n    /// <summary>\n    /// Methods for guarding against exception throwing values.\n    /// </summary>\n    internal static class Guard\n    {\n        /// <summary>\n        /// Throw an exception if the value is null.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfNull([NotNull] object? value, [CallerArgumentExpression(\"value\")] string? paramName = null)\n        {\n            if (value is null)\n            {\n                throw new ArgumentNullException(paramName, \"Must not be null\");\n            }\n        }\n\n        /// <summary>\n        /// Throw an exception if the value is null or empty.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfNullOrEmpty([NotNull] string? value, [CallerArgumentExpression(\"value\")] string? paramName = null)\n#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.\n        {\n            if (string.IsNullOrEmpty(value))\n            {\n                throw new ArgumentException(\"Must not be null or empty\", paramName);\n            }\n        }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs#L48-L84","documentation":"This is an ArgumentNullException thrown by Guard.ThrowIfNull in the vendored OpenTelemetry Kafka instrumentation's shared Guard helper. It fires whenever a caller passes null to a public API parameter that the library requires to be non-null, using CallerArgumentExpression to name the offending parameter. It is a programming/contract error, not a runtime environmental failure.","triggerScenarios":"Any call into the ConfluentKafka instrumentation (or code paths it guards) passing null for a required object parameter, e.g. a null consumer/producer, null configuration, or null callback argument that is forwarded to Guard.ThrowIfNull.","commonSituations":"Constructing tracing options with an unset consumer/producer reference; passing null delegates or state objects; refactoring that removed an initialization step so a field is still null when handed to the instrumentation.","solutions":["Inspect the paramName in the ArgumentNullException and initialize/assign the referenced argument before the call.","Add Guard.ThrowIfNull (or ArgumentNullException.ThrowIfNull) at your own boundary to fail fast at the point of the bug.","Check nullable-reference-type warnings at the call site; enabling <Nullable>enable</Nullable> surfaces the null flow at compile time."],"exampleFix":"// before\nAddConsumer(consumer: null);\n\n// after\nvar consumer = consumerBuilder.Build();\nAddConsumer(consumer);","handlingStrategy":"validation","validationCode":"if (value is null)\n{\n    throw new ArgumentNullException(nameof(value));\n}","typeGuard":"static bool IsNotNull<T>([NotNullWhen(true)] T? value) where T : class => value is not null;","tryCatchPattern":"try\n{\n    instrumented.Call(requiredArg);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"requiredArg\")\n{\n    logger.LogError(ex, \"requiredArg was null\");\n}","preventionTips":["Enable nullable reference types so nulls are caught at compile time","Null-check arguments at your own API boundaries before invoking the instrumentation","Initialize dependencies (consumer/producer/multiplexer) before registering them with the instrumentation"],"tags":["argument-null","validation","opentelemetry","kafka"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}