{"record":{"id":"d07c3dd849885dc8","repo":"TheAlgorithms/C-Sharp","slug":"searchitem","errorCode":null,"errorMessage":"searchItem","messagePattern":"searchItem","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Search/JumpSearcher.cs","lineNumber":27,"sourceCode":"/// <typeparam name=\"T\">Type of the array element.</typeparam>\npublic class JumpSearcher<T> where T : IComparable<T>\n{\n    /// <summary>\n    ///     Find the index of the item searched for in the array.\n    /// </summary>\n    /// <param name=\"sortedArray\">Sorted array to be search in. Cannot be null.</param>\n    /// <param name=\"searchItem\">Item to be search for. Cannot be null.</param>\n    /// <returns>If item is found, return index. If array is empty or item not found, return -1.</returns>\n    public int FindIndex(T[] sortedArray, T searchItem)\n    {\n        if (sortedArray is null)\n        {\n            throw new ArgumentNullException(\"sortedArray\");\n        }\n\n        if (searchItem is null)\n        {\n            throw new ArgumentNullException(\"searchItem\");\n        }\n\n        int jumpStep = (int)Math.Floor(Math.Sqrt(sortedArray.Length));\n        int currentIndex = 0;\n        int nextIndex = jumpStep;\n\n        if (sortedArray.Length != 0)\n        {\n            while (sortedArray[nextIndex - 1].CompareTo(searchItem) < 0)\n            {\n                currentIndex = nextIndex;\n                nextIndex += jumpStep;\n\n                if (nextIndex >= sortedArray.Length)\n                {\n                    nextIndex = sortedArray.Length - 1;\n                    break;\n                }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Search/JumpSearcher.cs#L9-L45","documentation":"JumpSearcher.FindIndex throws ArgumentNullException(\"searchItem\") when the value to search for is null. Jump search compares elements with ordering comparisons that are undefined for null, so the null key is rejected during argument validation.","triggerScenarios":"FindIndex(sortedArray, null) — null coming from optional parameters, uninitialized key variables, or nullable data models where the search field was never populated.","commonSituations":"Search boxes/inputs bound to nullable properties; records where an optional key is absent; generic code where default(T) is null for reference types and is passed through unchecked.","solutions":["Short-circuit before the call: if (searchItem is null) return -1;","Ensure default(T) is not leaked into the search path in generic wrappers.","Populate or default the key at the source (form binding, DTO default) so it is never null.","Catch ArgumentNullException and map it to a not-found result if null keys are an expected input state."],"exampleFix":"// before\nreturn jumper.FindIndex(sortedArray, key);\n// after\nif (key is null) return -1;\nreturn jumper.FindIndex(sortedArray, key);","handlingStrategy":"validation","validationCode":"if (searchItem is null) return -1;","typeGuard":"bool IsValidKey<T>(T? key) => key is not null;","tryCatchPattern":"try { return jumper.FindIndex(sortedArray, searchItem); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"searchItem\") { return -1; }","preventionTips":["Never pass default(T) of a reference type straight into search APIs.","Bind optional UI inputs to non-nullable defaults or empty sentinels.","Validate the key in your own service layer before delegating to the searcher.","Add assertions in tests for null-key behavior."],"tags":["null-argument","search","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}