浏览代码

Fix nullability errors in Emby.Server.Implementations

crobibero 4 年之前
父节点
当前提交
7bf320922c

+ 8 - 2
Emby.Server.Implementations/AppBase/ConfigurationHelper.cs

@@ -35,7 +35,8 @@ namespace Emby.Server.Implementations.AppBase
             }
             catch (Exception)
             {
-                configuration = Activator.CreateInstance(type);
+                var instanceConfiguration = Activator.CreateInstance(type);
+                configuration = instanceConfiguration ?? throw new NullReferenceException(nameof(instanceConfiguration));
             }
 
             using var stream = new MemoryStream(buffer?.Length ?? 0);
@@ -48,8 +49,13 @@ namespace Emby.Server.Implementations.AppBase
             // If the file didn't exist before, or if something has changed, re-save
             if (buffer == null || !newBytes.AsSpan(0, newBytesLen).SequenceEqual(buffer))
             {
-                Directory.CreateDirectory(Path.GetDirectoryName(path));
+                var directory = Path.GetDirectoryName(path);
+                if (directory == null)
+                {
+                    throw new NullReferenceException(nameof(directory));
+                }
 
+                Directory.CreateDirectory(directory);
                 // Save it after load in case we got new items
                 using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                 {

+ 5 - 0
Emby.Server.Implementations/Cryptography/CryptographyProvider.cs

@@ -81,6 +81,11 @@ namespace Emby.Server.Implementations.Cryptography
             }
 
             using var h = HashAlgorithm.Create(hashMethod);
+            if (h == null)
+            {
+                throw new NullReferenceException(nameof(h));
+            }
+
             if (salt.Length == 0)
             {
                 return h.ComputeHash(bytes);

+ 6 - 1
Emby.Server.Implementations/Session/WebSocketController.cs

@@ -55,8 +55,13 @@ namespace Emby.Server.Implementations.Session
             connection.Closed += OnConnectionClosed;
         }
 
-        private void OnConnectionClosed(object sender, EventArgs e)
+        private void OnConnectionClosed(object? sender, EventArgs e)
         {
+            if (sender == null)
+            {
+                throw new NullReferenceException(nameof(sender));
+            }
+
             var connection = (IWebSocketConnection)sender;
             _logger.LogDebug("Removing websocket from session {Session}", _session.Id);
             _sockets.Remove(connection);