{"record":{"id":"a45b89b54a529dd5","repo":"HandyOrg/HandyControl","slug":"the-integer-value-must-be-bounded-with-0-1","errorCode":null,"errorMessage":"The integer value must be bounded with [{0}, {1})","messagePattern":"The integer value must be bounded with \\[(.+?), (.+?)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":180,"sourceCode":"\n    [DebuggerStepThrough]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    public static void UriIsAbsolute(Uri uri, string parameterName)\n    {\n        Verify.IsNotNull<Uri>(uri, parameterName);\n        if (!uri.IsAbsoluteUri)\n        {\n            throw new ArgumentException(\"The URI must be absolute.\", parameterName);\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    [DebuggerStepThrough]\n    public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)\n    {\n        if (value < lowerBoundInclusive || value >= upperBoundExclusive)\n        {\n            throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, \"The integer value must be bounded with [{0}, {1})\", new object[]\n            {\n                lowerBoundInclusive,\n                upperBoundExclusive\n            }), parameterName);\n        }\n    }\n\n    [DebuggerStepThrough]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive, string message, string parameter)\n    {\n        if (value < lowerBoundInclusive || value > upperBoundInclusive)\n        {\n            throw new ArgumentException(message, parameter);\n        }\n    }\n\n    [DebuggerStepThrough]","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs#L162-L198","documentation":"Verify.BoundedInteger checks that an integer argument falls within [lowerBoundInclusive, upperBoundExclusive). The library throws ArgumentException with a formatted message naming the expected bounds when the value is outside the range.","triggerScenarios":"Passing an int to an API backed by Verify.BoundedInteger where value < lowerBoundInclusive or value >= upperBoundExclusive — e.g. negative values where a non-negative count/index is required, or a value equal to the exclusive upper bound.","commonSituations":"Off-by-one errors (using an exclusive bound as if inclusive), passing -1 or sentinel values as counts, uninitialized/default values of 0 where a positive number is required.","solutions":["Clamp or validate the integer before the call: if (v < lo || v >= hi) ...","Use Math.Max(lo, Math.Min(hi - 1, value)) to coerce into range when clamping is acceptable","Fix off-by-one logic at the call site so the value is one below the exclusive upper bound at most"],"exampleFix":"// before\nVerifyTarget(value: count, lower: 0, upper: items.Count); // count == items.Count throws\n// after\nif (count < 0 || count >= items.Count) throw new ArgumentOutOfRangeException(nameof(count));\nVerifyTarget(value: count, lower: 0, upper: items.Count);","handlingStrategy":"validation","validationCode":"if (value < lowerBound || value >= upperBound) throw new ArgumentOutOfRangeException(nameof(value), value, $\"Must be in [{lowerBound}, {upperBound})\");","typeGuard":"bool InRange(int v, int lo, int hi) => v >= lo && v < hi;","tryCatchPattern":"try { api.Call(value); } catch (ArgumentException ex) when (ex.Message.StartsWith(\"The integer value must be bounded\")) { value = Math.Max(lo, Math.Min(hi - 1, value)); api.Call(value); }","preventionTips":["Remember the upper bound is EXCLUSIVE","Clamp computed values before passing","Avoid sentinel values like -1 as counts"],"tags":["argument-validation","range-check","integer"],"backgroundTag":"argument-out-of-range","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}