{"record":{"id":"9e391155dd408973","repo":"Humanizr/Humanizer","slug":"argument-must-be-non-negative","errorCode":null,"errorMessage":"Argument must be non-negative.","messagePattern":"Argument must be non-negative\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/PolyfillShims.cs","lineNumber":32,"sourceCode":"    extension(ArgumentNullException)\n    {\n        [Intrinsic]\n        public static void ThrowIfNull(\n            object? argument,\n            [CallerArgumentExpression(nameof(argument))] string? paramName = null)\n            => _ = argument ?? throw new ArgumentNullException(paramName);\n    }\n\n    extension(ArgumentOutOfRangeException)\n    {\n        /// <summary>Throws an <see cref=\"ArgumentOutOfRangeException\"/> if <paramref name=\"value\"/> is negative.</summary>\n        /// <param name=\"value\">The argument to validate as non-negative.</param>\n        /// <param name=\"paramName\">The name of the parameter with which <paramref name=\"value\"/> corresponds.</param>\n        public static void ThrowIfNegative(int value, [CallerArgumentExpression(nameof(value))] string? paramName = null)\n        {\n            if (value < 0)\n            {\n                throw new ArgumentOutOfRangeException(paramName, value, \"Argument must be non-negative.\");\n            }\n        }\n    }\n\n    // ---- Double ----\n    extension(double)\n    {\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static bool IsFinite(double x)\n        {\n            var bits = (ulong)BitConverter.DoubleToInt64Bits(x);\n            return (bits & 0x7FF0_0000_0000_0000UL) != 0x7FF0_0000_0000_0000UL;\n        }\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static bool IsIntegral(double x)\n        {\n            if (!IsFinite(x))","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/PolyfillShims.cs#L14-L50","documentation":"This is a polyfill implementation of ArgumentOutOfRangeException.ThrowIfNegative(int) for .NET Framework 4.8 and other pre-NET5 targets. It fires whenever an internal Humanizer API validates that a count or index is non-negative and the caller passed a negative value. On NET5+ the runtime's built-in method is used instead.","triggerScenarios":"Any internal Humanizer API on net48 that delegates to ArgumentOutOfRangeException.ThrowIfNegative with a negative int argument (e.g. negative precision, negative digit count). The polyfill is compiled only when NET5_0_OR_GREATER is not defined.","commonSituations":"Running on net48 with a caller that passes -1 for a parameter Humanizer validates. Mixing versions where a previously-unvalidated parameter now has a guard. Fuzzing or unit tests with negative edge cases.","solutions":["Ensure all integer arguments passed to Humanizer extension methods are non-negative.","Add input validation in your calling code before invoking Humanizer APIs.","If on net48 specifically, audit callsites that might pass negative counts."],"exampleFix":"// before\nvar h = TimeSpan.Humanize(precision: -1);\n\n// after\nvar h = TimeSpan.Humanize(precision: Math.Max(0, precision));","handlingStrategy":"validation","validationCode":"ArgumentOutOfRangeException.ThrowIfNegative(myValue);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate integer inputs for non-negativity before calling Humanizer APIs.","On net48, be especially careful since the polyfill is active.","Fuzz negative boundary values in your tests."],"tags":["polyfill","net48","argument-validation","range-check"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}