{"record":{"id":"d8afa2c9754c7f40","repo":"Unity-Technologies/UnityCsReference","slug":"path-cannot-be-null-or-empty","errorCode":null,"errorMessage":"Path cannot be null or empty.","messagePattern":"Path cannot be null or empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/FileUtil.cs","lineNumber":26,"sourceCode":"using System.IO;\nusing System.Text.RegularExpressions;\nusing UnityEngine;\nusing UnityEngine.Bindings;\nusing UnityEngine.Scripting;\n\nnamespace UnityEditor\n{\n    public partial class FileUtil\n    {\n        const string k_UdsPathPrefix = \"uds:/\";\n\n        /// Opens a file for reading. For UDS paths (uds:/...), returns a zero-copy\n        /// stream backed by native shared memory. For physical paths, returns a\n        /// standard FileStream. For other VFS paths, materialises via native read\n        public static Stream OpenRead(string path)\n        {\n            if (string.IsNullOrEmpty(path))\n                throw new ArgumentException(\"Path cannot be null or empty.\", nameof(path));\n\n            var physicalPath = FileUtil.GetPhysicalPath(path);\n\n            if (string.IsNullOrEmpty(physicalPath))\n            {\n                // Path exists in VFS but not on the physical filesystem —\n                // materialise the data through the native VFS read\n                byte[] data = ReadAllBytesInternal(path);\n                return new MemoryStream(data, writable: false);\n            }\n\n            // The 'physical' path for a VirtualArtifact will be a UDS virtual path\n            if (physicalPath.StartsWith(k_UdsPathPrefix, StringComparison.Ordinal))\n                return OpenReadUDS(physicalPath);\n\n            // Fall back to opening the physical file in the normal way\n            return File.Open(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);\n        }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/FileUtil.cs#L8-L44","documentation":"FileUtil.OpenRead (the newer Stream-returning overload in FileUtil.cs) guards its path argument with string.IsNullOrEmpty and throws ArgumentException if either holds. Unlike the bindings-layer Delete/Copy guards, this also rejects empty uniformly with null because the subsequent GetPhysicalPath and VFS lookup cannot proceed on an absent path.","triggerScenarios":"Calling FileUtil.OpenRead(null) or FileUtil.OpenRead(\"\"). Passing a path from a lookup (AssetDatabase, config) that resolved to null or empty. Streaming-assets reads where the relative path was concatenated to an unset base.","commonSituations":"Reading an asset whose path lookup failed; reading a config file whose location was not configured; editor tooling that reads a file chosen via ObjectField that the user cleared.","solutions":["Validate the path with string.IsNullOrEmpty (or IsNullOrWhiteSpace) before opening.","Where the path is computed, ensure each component (base dir, relative) is non-empty.","Provide a clear early error naming the missing field rather than letting the ArgumentException bubble."],"exampleFix":"// before\nusing Stream s = FileUtil.OpenRead(path);\n// after\nif (string.IsNullOrEmpty(path)) throw new ArgumentException(\"path required\", nameof(path));\nusing Stream s = FileUtil.OpenRead(path);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(path))\n    throw new ArgumentException(\"path required\", nameof(path));\nusing Stream s = FileUtil.OpenRead(path);","typeGuard":"static bool IsReadablePath(string p) => !string.IsNullOrEmpty(p);","tryCatchPattern":null,"preventionTips":["Guard all OpenRead call sites with string.IsNullOrEmpty.","Validate the lookup/config that produces the path before reading.","Surface a descriptive early error instead of letting the ArgumentException bubble."],"tags":["filesystem","argument","validation","stream","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}