{"record":{"id":"c15b559e119d742e","repo":"JamesNK/Newtonsoft.Json","slug":"start","errorCode":null,"errorMessage":"start","messagePattern":"start","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/StringUtils.cs","lineNumber":344,"sourceCode":"            return (source.Length > 0 && source[0] == value);\n        }\n\n        public static bool EndsWith(this string source, char value)\n        {\n            return (source.Length > 0 && source[source.Length - 1] == value);\n        }\n\n        public static string Trim(this string s, int start, int length)\n        {\n            // References: https://referencesource.microsoft.com/#mscorlib/system/string.cs,2691\n            // https://referencesource.microsoft.com/#mscorlib/system/string.cs,1226\n            if (s == null)\n            {\n                throw new ArgumentNullException();\n            }\n            if (start < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(start));\n            }\n            if (length < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(length));\n            }\n            int end = start + length - 1;\n            if (end >= s.Length)\n            {\n                throw new ArgumentOutOfRangeException(nameof(length));\n            }\n            for (; start < end; start++)\n            {\n                if (!char.IsWhiteSpace(s[start]))\n                {\n                    break;\n                }\n            }\n            for (; end >= start; end--)","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/StringUtils.cs#L326-L362","documentation":"Thrown by StringUtils.Trim(string s, int start, int length) when start is negative — an ArgumentOutOfRangeException with paramName \"start\". This internal helper trims whitespace from a substring range of a string and is used during type-name parsing and other internal trimming operations. Negative start is invalid for any substring operation.","triggerScenarios":"Calling StringUtils.Trim with a negative start argument. Typically this surfaces indirectly when internal Json.NET helpers (e.g. SplitFullyQualifiedTypeName / type-name trimming) receive malformed input that produces a negative computed start.","commonSituations":"Corrupt or malformed fully-qualified type names processed under TypeNameHandling, custom code calling this internal API with bad offsets, or crafted JSON that triggers internal trimming with invalid bounds.","solutions":["Ensure any computed start index passed to Trim is non-negative.","Sanitize/validate input strings (especially type names) before Json.NET processes them.","Avoid calling this internal helper directly; prefer public string.Trim with valid ranges."],"exampleFix":"// before\nstring t = StringUtils.Trim(name, computedStart, length); // computedStart < 0\n\n// after\nint computedStart = Math.Max(0, computedStartRaw);\nstring t = StringUtils.Trim(name, computedStart, length);","handlingStrategy":"validation","validationCode":"if (start < 0) throw new ArgumentOutOfRangeException(nameof(start));\nstring t = StringUtils.Trim(s, start, length);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp computed start indices with Math.Max(0, value) before passing to Trim.","Validate string inputs (especially type names under TypeNameHandling) before processing.","Prefer public string.Trim over this internal helper in your own code."],"tags":["string","argument","validation","trim","internal"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}