{"record":{"id":"8866279d07d494de","repo":"Unity-Technologies/UnityCsReference","slug":"array-is-invalid","errorCode":null,"errorMessage":"Array is invalid.","messagePattern":"Array is invalid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TargetChoiceHandler.cs","lineNumber":151,"sourceCode":"            }\n\n            if (!PrefabUtility.HasSameParent(gameObjects))\n                throw new ArgumentException(nameof(gameObjects), \"ApplyPrefabAddedGameObjects requires that GameObjects share the same parent.\");\n\n            if (!HasSameAssetPath(infos))\n                throw new ArgumentException(nameof(infos), \"ApplyPrefabAddedGameObjects requires that GameObjects share the same parent asset path.\");\n\n            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(infos[0].assetPath, PrefabUtility.SaveVerb.Apply))\n                return;\n\n            PrefabUtility.ApplyAddedGameObjects(gameObjects, infos[0].assetPath, InteractionMode.UserAction);\n            EditorUtility.ForceRebuildInspectors();\n        }\n\n        internal static bool HasSameAssetPath(ObjectInstanceAndSourcePathInfo[] infos)\n        {\n            if (infos == null || infos.Length == 0)\n                throw new ArgumentException(nameof(infos), \"Array is invalid.\");\n\n            string assetPath = infos[0].assetPath;\n            for (int i = 1; i < infos.Length; i++)\n            {\n                if (assetPath != infos[i].assetPath)\n                    return false;\n            }\n\n            return true;\n        }\n\n        internal static void RevertPrefabAddedGameObjects(object userData)\n        {\n            GameObject[] gameObjects = (GameObject[])userData;\n\n            foreach (GameObject go in gameObjects)\n                PrefabUtility.RevertAddedGameObject(go, InteractionMode.UserAction);\n","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TargetChoiceHandler.cs#L133-L169","documentation":"Thrown by HasSameAssetPath when the input infos array is null or has zero elements. The method cannot determine a common asset path without at least one entry, so it rejects the input as invalid rather than returning a misleading result.","triggerScenarios":"Calling HasSameAssetPath with a null array or an empty ObjectInstanceAndSourcePathInfo[]; an upstream selection that produced no items being forwarded unfiltered.","commonSituations":"Empty user selection passed through to apply logic; a filtering step that removed all entries but did not short-circuit before validation.","solutions":["Guard callers: return early (no-op) when the selection is empty or null before reaching HasSameAssetPath.","Initialize infos from a validated non-empty selection.","Assert the count > 0 at the UI boundary and disable the apply action for empty selections."],"exampleFix":"// before\nif (!HasSameAssetPath(infos)) { /* ... */ } // infos may be empty\n\n// after\nif (infos == null || infos.Length == 0) return;\nif (!HasSameAssetPath(infos)) { /* ... */ }","handlingStrategy":"validation","validationCode":"if (infos == null || infos.Length == 0) { /* skip, nothing to do */ return; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Short-circuit empty selections before invoking apply/validation.","Disable Apply when selection count is zero.","Treat null/empty as a no-op, not an error, at the UI boundary."],"tags":["unity-editor","prefab","null-check","argument"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}