aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrobibero <cody@robibe.ro>2020-11-13 09:41:18 -0700
committercrobibero <cody@robibe.ro>2020-11-13 09:41:18 -0700
commit7bf320922c095b67293c05b8d2e0ed79f1db78d7 (patch)
tree2f49f41b3c3c66d24f55d1c9faa1639dadc022f1
parentd5e2369dd6ac308e518a5a36a744a1a2dac45f70 (diff)
Fix nullability errors in Emby.Server.Implementations
-rw-r--r--Emby.Server.Implementations/AppBase/ConfigurationHelper.cs10
-rw-r--r--Emby.Server.Implementations/Cryptography/CryptographyProvider.cs5
-rw-r--r--Emby.Server.Implementations/Session/WebSocketController.cs7
3 files changed, 19 insertions, 3 deletions
diff --git a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs b/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs
index 4c9ab33a7..e19ce5edf 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-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))
{
diff --git a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs
index fd302d136..a48b6f356 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.cs
index b986ffa1c..7559ccb78 100644
--- a/Emby.Server.Implementations/Session/WebSocketController.cs
+++ b/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);