{"record":{"id":"221ea9673563a29d","repo":"Unity-Technologies/UnityCsReference","slug":"container","errorCode":null,"errorMessage":"container","messagePattern":"container","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Audio/AudioRandomContainerExtensions.cs","lineNumber":55,"sourceCode":"        ValidateContainer(container);\n\n        if (clips == null)\n            throw new ArgumentNullException(nameof(clips));\n\n        if (clips.Length == 0)\n            throw new ArgumentException(\"Must not be empty.\", nameof(clips));\n\n        AddElementsInner(container, clips.Length, (i, element) =>\n        {\n            if (clips[i] != null)\n                element.audioClip = clips[i];\n        });\n    }\n\n    static void ValidateContainer(AudioRandomContainer container)\n    {\n        if (container == null)\n            throw new ArgumentNullException(nameof(container));\n\n        if (!EditorUtility.IsPersistent(container))\n            throw new ArgumentException(\"Must be a persistent asset.\", nameof(container));\n    }\n\n    static void AddElementsInner(AudioRandomContainer container, int count,\n        Action<int, AudioContainerElement> configureElement)\n    {\n        var undoGroupName = count > 1 ? $\"{k_BaseAddElementsUndoName}s\" : k_BaseAddElementsUndoName;\n\n        Undo.RegisterCompleteObjectUndo(container, undoGroupName);\n        Undo.SetCurrentGroupName(undoGroupName);\n\n        if (container.elements == null)\n            container.elements = Array.Empty<AudioContainerElement>();\n\n        var newElements = new AudioContainerElement[count];\n        var oldAndNewElements = new AudioContainerElement[container.elements.Length + count];","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Audio/AudioRandomContainerExtensions.cs#L37-L73","documentation":"ArgumentNullException thrown by ValidateContainer when the container parameter is null. This is the first guard in the validation chain for all AudioRandomContainer extension methods, ensuring the target container is a valid object before any operations are performed on it.","triggerScenarios":"Calling any AddElements overload (or any method using ValidateContainer) with a null AudioRandomContainer. Occurs when a SerializedObject.targetObject cast fails, when a script references a container that was destroyed, or when a field is unassigned.","commonSituations":"Editor windows with unassigned container references, scripts that destroy or null-out a container before a deferred AddElements call, deserialized assets where the container reference is missing, component lookups that return null.","solutions":["Null-check the container before calling AddElements or any extension method.","Ensure the AudioRandomContainer asset is assigned in the inspector or created before use.","If using SerializedObject, verify targetObject is not null and is of the correct type before casting.","Add a Debug.LogError or early-return when the container reference is missing to aid debugging."],"exampleFix":"// before\ncontainer.AddElements(clips); // container may be null\n// after\nif (container == null)\n{\n    Debug.LogError(\"AudioRandomContainer is not assigned.\");\n    return;\n}\ncontainer.AddElements(clips);","handlingStrategy":"type-guard","validationCode":"// Null-check container before calling any extension method\nif (container != null)\n    container.AddElements(clips);","typeGuard":"static bool IsValidContainer(AudioRandomContainer container) => container != null;","tryCatchPattern":null,"preventionTips":["Always null-check AudioRandomContainer references before calling extension methods.","Verify SerializedObject.targetObject is not null before casting to AudioRandomContainer.","Guard against destroyed or unloaded assets with null checks.","Use [SerializeField] with [NotNull] attributes or initialization to reduce null risk."],"tags":["audio","editor","validation","null-check","argument-validation","audio-random-container"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}