{"record":{"id":"ce34a2061bca99dc","repo":"EllanJiang/GameFramework","slug":"results-is-invalid-fsmmanager","errorCode":null,"errorMessage":"Results is invalid.","messagePattern":"Results is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Fsm/FsmManager.cs","lineNumber":224,"sourceCode":"            int index = 0;\n            FsmBase[] results = new FsmBase[m_Fsms.Count];\n            foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)\n            {\n                results[index++] = fsm.Value;\n            }\n\n            return results;\n        }\n\n        /// <summary>\n        /// 获取所有有限状态机。\n        /// </summary>\n        /// <param name=\"results\">所有有限状态机。</param>\n        public void GetAllFsms(List<FsmBase> results)\n        {\n            if (results == null)\n            {\n                throw new GameFrameworkException(\"Results is invalid.\");\n            }\n\n            results.Clear();\n            foreach (KeyValuePair<TypeNamePair, FsmBase> fsm in m_Fsms)\n            {\n                results.Add(fsm.Value);\n            }\n        }\n\n        /// <summary>\n        /// 创建有限状态机。\n        /// </summary>\n        /// <typeparam name=\"T\">有限状态机持有者类型。</typeparam>\n        /// <param name=\"owner\">有限状态机持有者。</param>\n        /// <param name=\"states\">有限状态机状态集合。</param>\n        /// <returns>要创建的有限状态机。</returns>\n        public IFsm<T> CreateFsm<T>(T owner, params FsmState<T>[] states) where T : class\n        {","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Fsm/FsmManager.cs#L206-L242","documentation":"GetAllFsms fills the provided list with all finite state machines registered in the FsmManager. The library throws GameFrameworkException(\"Results is invalid.\") when the results list argument is null, because it needs a caller-allocated list to clear and fill.","triggerScenarios":"Calling FsmManager.GetAllFsms(null) — the only condition that raises this exception, checked at the very top of the method.","commonSituations":"Passing an uninitialized field or a method result that was null instead of an instantiated List<FsmBase>; refactoring code so a list variable became nullable; copying an overload pattern where the container was never created.","solutions":["Instantiate the list before calling: GetAllFsms(new List<FsmBase>())","Check the list for null before the call, or use a factory method that always returns a non-null list","Wrap the call in try-catch for GameFrameworkException if the list source is external/untrusted"],"exampleFix":"// before\nList<FsmBase> results = GetListFromCache(); // may be null\nfsmManager.GetAllFsms(results);\n// after\nList<FsmBase> results = GetListFromCache() ?? new List<FsmBase>();\nfsmManager.GetAllFsms(results);","handlingStrategy":"validation","validationCode":"if (results == null) results = new List<FsmBase>();\nfsmManager.GetAllFsms(results);","typeGuard":null,"tryCatchPattern":"try { fsmManager.GetAllFsms(results); }\ncatch (GameFrameworkException ex) { Log.Error(\"GetAllFsms failed: {0}\", ex.Message); }","preventionTips":["Never pass null collections as output parameters","Initialize list fields at declaration","Prefer the overload that returns a new collection if available"],"tags":["csharp","fsm","null-argument"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}