{"record":{"id":"1b8b25cf132bfddc","repo":"Unity-Technologies/UnityCsReference","slug":"clips","errorCode":null,"errorMessage":"clips","messagePattern":"clips","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Audio/AudioRandomContainerExtensions.cs","lineNumber":40,"sourceCode":"        ValidateContainer(container);\n\n        if (count <= 0)\n            throw new ArgumentOutOfRangeException(nameof(count), \"Must be greater than zero.\");\n\n        AddElementsInner(container, count, (i, element) => { });\n    }\n\n    /// <summary>\n    /// Adds a given number of new <see cref=\"AudioContainerElement\"/> objects with clips assigned to <see cref=\"AudioRandomContainer.elements\"/>.\n    /// </summary>\n    /// <param name=\"container\">The instance to add the elements to.</param>\n    /// <param name=\"clips\">An array of <see cref=\"AudioClip\"/> objects to be assigned to each new element.</param>\n    internal static void AddElements(this AudioRandomContainer container, AudioClip[] clips)\n    {\n        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));","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Audio/AudioRandomContainerExtensions.cs#L22-L58","documentation":"ArgumentNullException thrown by AudioRandomContainerExtensions.AddElements(AudioClip[] clips) when the clips array is null. This is a standard null-argument guard ensuring the clips parameter is a valid array before accessing its Length property.","triggerScenarios":"Calling container.AddElements(null) or passing a variable that was never assigned. Occurs when a clips array field is uninitialized, a serialized property resolves to null, or a code path skips array initialization before calling AddElements.","commonSituations":"Editor scripts that read an AudioClip[] from a SerializedProperty that is unassigned, drag-and-drop handlers where no clips were dropped, deserialized data with missing clip arrays, conditional code paths that leave the array null.","solutions":["Initialize the clips array before passing it, or check for null before calling AddElements.","If clips may legitimately be absent, guard the call: if (clips != null) container.AddElements(clips);","Ensure SerializedProperty.arraySize > 0 before extracting AudioClip elements into an array.","Use Array.Empty<AudioClip>() as a default instead of null, then let the empty-check guide behavior."],"exampleFix":"// before\ncontainer.AddElements(myClips); // myClips may be null\n// after\nif (myClips != null && myClips.Length > 0)\n    container.AddElements(myClips);","handlingStrategy":"type-guard","validationCode":"// Null-check clips before calling AddElements\nif (clips != null)\n    container.AddElements(clips);","typeGuard":"static bool IsValidClipsArray(AudioClip[] clips) => clips != null && clips.Length > 0;","tryCatchPattern":null,"preventionTips":["Initialize AudioClip arrays with Array.Empty<AudioClip>() rather than leaving them null.","Null-check arrays read from SerializedProperty before use.","Assign default-empty arrays in field initializers to avoid null propagation.","Validate array references from deserialized or network data before passing to editor APIs."],"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"}