{"record":{"id":"99da9c5c6cdbe237","repo":"EllanJiang/GameFramework","slug":"data-bytes-is-invalid","errorCode":null,"errorMessage":"Data bytes is invalid.","messagePattern":"Data bytes is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/DataProvider/DataProvider.cs","lineNumber":300,"sourceCode":"                if (exception is GameFrameworkException)\n                {\n                    throw;\n                }\n\n                throw new GameFrameworkException(Utility.Text.Format(\"Can not parse data string with exception '{0}'.\", exception), exception);\n            }\n        }\n\n        /// <summary>\n        /// 解析内容。\n        /// </summary>\n        /// <param name=\"dataBytes\">要解析的内容二进制流。</param>\n        /// <returns>是否解析内容成功。</returns>\n        public bool ParseData(byte[] dataBytes)\n        {\n            if (dataBytes == null)\n            {\n                throw new GameFrameworkException(\"Data bytes is invalid.\");\n            }\n\n            return ParseData(dataBytes, 0, dataBytes.Length, null);\n        }\n\n        /// <summary>\n        /// 解析内容。\n        /// </summary>\n        /// <param name=\"dataBytes\">要解析的内容二进制流。</param>\n        /// <param name=\"userData\">用户自定义数据。</param>\n        /// <returns>是否解析内容成功。</returns>\n        public bool ParseData(byte[] dataBytes, object userData)\n        {\n            if (dataBytes == null)\n            {\n                throw new GameFrameworkException(\"Data bytes is invalid.\");\n            }\n","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/DataProvider/DataProvider.cs#L282-L318","documentation":"The ParseData(byte[]) overload validates the byte array is non-null before forwarding to ParseData(byte[], int, int, object). A null array cannot be parsed, so it throws immediately. This is the byte-array analogue of the 'Data string is invalid.' check.","triggerScenarios":"Calling ParseData((byte[])null) — typically when a download/file read produced a null buffer and the result was passed straight into ParseData.","commonSituations":"WebRequest or file read failure returning null bytes; a field that was never assigned; test code probing null handling.","solutions":["Ensure the byte array is loaded and non-null before calling ParseData.","Fix the upstream load (file/network/resource) that produced a null buffer.","Guard with a null check and report a load failure instead of parsing."],"exampleFix":"// before\nbyte[] bytes = LoadBytes(); // null on failure\nbool ok = dataProvider.ParseData(bytes);\n// after\nbyte[] bytes = LoadBytes();\nif (bytes != null && bytes.Length > 0) { bool ok = dataProvider.ParseData(bytes); }","handlingStrategy":"validation","validationCode":"if (dataBytes == null || dataBytes.Length == 0) { /* handle missing bytes */ }\nbool ok = dataProvider.ParseData(dataBytes);","typeGuard":"bool IsParseable(byte[] b) => b != null && b.Length > 0;","tryCatchPattern":"try { dataProvider.ParseData(bytes); }\ncatch (GameFrameworkException e) when (e.Message == \"Data bytes is invalid.\") { Log.Error(\"Byte buffer was null; check upstream load.\"); }","preventionTips":["Null-check download/file-read results before parsing.","Return empty arrays or throw descriptive errors from loaders instead of null."],"tags":["null-argument","validation","parse"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}