The Free Software Media System - Server Backend & API
Fix nullability errors in Emby.Server.Implementations
crobibero7bf320922c09
diff --git a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs b/Emby.Server.Implementations/AppBase/ConfigurationHelper.csindex 4c9ab33a7c..e19ce5edf8 100644--- a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs+++ b/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-saveif (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 itemsusing (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)){diff --git a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Server.Implementations/Cryptography/CryptographyProvider.csindex fd302d1365..a48b6f3563 100644--- a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs+++ b/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);diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.csindex b986ffa1cd..7559ccb782 100644--- a/Emby.Server.Implementations/Session/WebSocketController.cs+++ b/Emby.Server.Implementations/Session/WebSocketController.cs@@ -55,8 +55,13 @@ namespace Emby.Server.Implementations.Sessionconnection.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);