浏览代码

Merge pull request #5982 from Bond-009/nullable

Bond-009 4 年之前
父节点
当前提交
a4a3f598af
共有 44 个文件被更改,包括 145 次插入165 次删除
  1. 3 2
      Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
  2. 6 0
      Jellyfin.Api/Controllers/ConfigurationController.cs
  3. 2 0
      MediaBrowser.Common/Configuration/ConfigurationStore.cs
  4. 1 0
      MediaBrowser.Common/Configuration/ConfigurationUpdateEventArgs.cs
  5. 2 0
      MediaBrowser.Common/Configuration/IApplicationPaths.cs
  6. 0 1
      MediaBrowser.Common/Cryptography/PasswordHash.cs
  7. 2 2
      MediaBrowser.Common/Events/EventHelper.cs
  8. 0 2
      MediaBrowser.Common/Extensions/BaseExtensions.cs
  9. 0 2
      MediaBrowser.Common/Extensions/CopyToExtensions.cs
  10. 1 1
      MediaBrowser.Common/Extensions/HttpContextExtensions.cs
  11. 0 2
      MediaBrowser.Common/Extensions/MethodNotAllowedException.cs
  12. 0 2
      MediaBrowser.Common/Extensions/ProcessExtensions.cs
  13. 0 1
      MediaBrowser.Common/Extensions/RateLimitExceededException.cs
  14. 0 2
      MediaBrowser.Common/Extensions/ResourceNotFoundException.cs
  15. 0 2
      MediaBrowser.Common/Extensions/ShuffleExtensions.cs
  16. 1 1
      MediaBrowser.Common/Extensions/SplitStringExtensions.cs
  17. 0 2
      MediaBrowser.Common/Extensions/StreamExtensions.cs
  18. 2 0
      MediaBrowser.Common/IApplicationHost.cs
  19. 3 54
      MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs
  20. 2 2
      MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs
  21. 81 0
      MediaBrowser.Common/Json/Converters/JsonDelimitedArrayConverter.cs
  22. 3 3
      MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs
  23. 12 6
      MediaBrowser.Common/Json/Converters/JsonOmdbNotAvailableStringConverter.cs
  24. 3 54
      MediaBrowser.Common/Json/Converters/JsonPipeDelimitedArrayConverter.cs
  25. 2 2
      MediaBrowser.Common/Json/Converters/JsonPipeDelimitedArrayConverterFactory.cs
  26. 4 4
      MediaBrowser.Common/Json/Converters/JsonStringConverter.cs
  27. 1 1
      MediaBrowser.Common/Json/Converters/JsonVersionConverter.cs
  28. 1 0
      MediaBrowser.Common/MediaBrowser.Common.csproj
  29. 0 1
      MediaBrowser.Common/Net/INetworkManager.cs
  30. 0 1
      MediaBrowser.Common/Net/IPHost.cs
  31. 0 1
      MediaBrowser.Common/Net/IPNetAddress.cs
  32. 0 1
      MediaBrowser.Common/Net/IPObject.cs
  33. 2 0
      MediaBrowser.Common/Plugins/BasePlugin.cs
  34. 2 0
      MediaBrowser.Common/Plugins/BasePluginOfT.cs
  35. 2 0
      MediaBrowser.Common/Plugins/IPlugin.cs
  36. 0 2
      MediaBrowser.Common/Plugins/IPluginManager.cs
  37. 0 1
      MediaBrowser.Common/Plugins/LocalPlugin.cs
  38. 0 2
      MediaBrowser.Common/Plugins/PluginManifest.cs
  39. 2 2
      MediaBrowser.Common/Progress/ActionableProgress.cs
  40. 1 1
      MediaBrowser.Common/Progress/SimpleProgress.cs
  41. 1 3
      MediaBrowser.Common/Providers/ProviderIdParsers.cs
  42. 0 2
      MediaBrowser.Common/Updates/IInstallationManager.cs
  43. 2 0
      MediaBrowser.Common/Updates/InstallationEventArgs.cs
  44. 1 0
      MediaBrowser.Common/Updates/InstallationFailedEventArgs.cs

+ 3 - 2
Jellyfin.Api/Auth/BaseAuthorizationHandler.cs

@@ -77,8 +77,9 @@ namespace Jellyfin.Api.Auth
                 return false;
                 return false;
             }
             }
 
 
-            var ip = _httpContextAccessor.HttpContext.GetNormalizedRemoteIp();
-            var isInLocalNetwork = _networkManager.IsInLocalNetwork(ip);
+            var isInLocalNetwork = _httpContextAccessor.HttpContext != null
+                && _networkManager.IsInLocalNetwork(_httpContextAccessor.HttpContext.GetNormalizedRemoteIp());
+
             // User cannot access remotely and user is remote
             // User cannot access remotely and user is remote
             if (!user.HasPermission(PermissionKind.EnableRemoteAccess) && !isInLocalNetwork)
             if (!user.HasPermission(PermissionKind.EnableRemoteAccess) && !isInLocalNetwork)
             {
             {

+ 6 - 0
Jellyfin.Api/Controllers/ConfigurationController.cs

@@ -1,3 +1,4 @@
+using System;
 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations;
 using System.Net.Mime;
 using System.Net.Mime;
 using System.Text.Json;
 using System.Text.Json;
@@ -94,6 +95,11 @@ namespace Jellyfin.Api.Controllers
         {
         {
             var configurationType = _configurationManager.GetConfigurationType(key);
             var configurationType = _configurationManager.GetConfigurationType(key);
             var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, _serializerOptions).ConfigureAwait(false);
             var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, _serializerOptions).ConfigureAwait(false);
+            if (configuration == null)
+            {
+                throw new ArgumentException("Body doesn't contain a valid configuration");
+            }
+
             _configurationManager.SaveConfiguration(key, configuration);
             _configurationManager.SaveConfiguration(key, configuration);
             return NoContent();
             return NoContent();
         }
         }

+ 2 - 0
MediaBrowser.Common/Configuration/ConfigurationStore.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System;
 using System;
 
 
 namespace MediaBrowser.Common.Configuration
 namespace MediaBrowser.Common.Configuration

+ 1 - 0
MediaBrowser.Common/Configuration/ConfigurationUpdateEventArgs.cs

@@ -1,3 +1,4 @@
+#nullable disable
 #pragma warning disable CS1591
 #pragma warning disable CS1591
 
 
 using System;
 using System;

+ 2 - 0
MediaBrowser.Common/Configuration/IApplicationPaths.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 namespace MediaBrowser.Common.Configuration
 namespace MediaBrowser.Common.Configuration
 {
 {
     /// <summary>
     /// <summary>

+ 0 - 1
MediaBrowser.Common/Cryptography/PasswordHash.cs

@@ -1,5 +1,4 @@
 #pragma warning disable CS1591
 #pragma warning disable CS1591
-#nullable enable
 
 
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;

+ 2 - 2
MediaBrowser.Common/Events/EventHelper.cs

@@ -17,7 +17,7 @@ namespace MediaBrowser.Common.Events
         /// <param name="sender">The sender.</param>
         /// <param name="sender">The sender.</param>
         /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
         /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
         /// <param name="logger">The logger.</param>
         /// <param name="logger">The logger.</param>
-        public static void QueueEventIfNotNull(EventHandler handler, object sender, EventArgs args, ILogger logger)
+        public static void QueueEventIfNotNull(EventHandler? handler, object sender, EventArgs args, ILogger logger)
         {
         {
             if (handler != null)
             if (handler != null)
             {
             {
@@ -43,7 +43,7 @@ namespace MediaBrowser.Common.Events
         /// <param name="sender">The sender.</param>
         /// <param name="sender">The sender.</param>
         /// <param name="args">The args.</param>
         /// <param name="args">The args.</param>
         /// <param name="logger">The logger.</param>
         /// <param name="logger">The logger.</param>
-        public static void QueueEventIfNotNull<T>(EventHandler<T> handler, object sender, T args, ILogger logger)
+        public static void QueueEventIfNotNull<T>(EventHandler<T>? handler, object sender, T args, ILogger logger)
         {
         {
             if (handler != null)
             if (handler != null)
             {
             {

+ 0 - 2
MediaBrowser.Common/Extensions/BaseExtensions.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 using System.Security.Cryptography;
 using System.Security.Cryptography;
 using System.Text;
 using System.Text;

+ 0 - 2
MediaBrowser.Common/Extensions/CopyToExtensions.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System.Collections.Generic;
 using System.Collections.Generic;
 
 
 namespace MediaBrowser.Common.Extensions
 namespace MediaBrowser.Common.Extensions

+ 1 - 1
MediaBrowser.Common/Extensions/HttpContextExtensions.cs

@@ -17,7 +17,7 @@ namespace MediaBrowser.Common.Extensions
         {
         {
             return (context.Connection.LocalIpAddress == null
             return (context.Connection.LocalIpAddress == null
                     && context.Connection.RemoteIpAddress == null)
                     && context.Connection.RemoteIpAddress == null)
-                   || context.Connection.LocalIpAddress.Equals(context.Connection.RemoteIpAddress);
+                   || Equals(context.Connection.LocalIpAddress, context.Connection.RemoteIpAddress);
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 0 - 2
MediaBrowser.Common/Extensions/MethodNotAllowedException.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 
 
 namespace MediaBrowser.Common.Extensions
 namespace MediaBrowser.Common.Extensions

+ 0 - 2
MediaBrowser.Common/Extensions/ProcessExtensions.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Threading;
 using System.Threading;

+ 0 - 1
MediaBrowser.Common/Extensions/RateLimitExceededException.cs

@@ -1,4 +1,3 @@
-#nullable enable
 #pragma warning disable CS1591
 #pragma warning disable CS1591
 
 
 using System;
 using System;

+ 0 - 2
MediaBrowser.Common/Extensions/ResourceNotFoundException.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 
 
 namespace MediaBrowser.Common.Extensions
 namespace MediaBrowser.Common.Extensions

+ 0 - 2
MediaBrowser.Common/Extensions/ShuffleExtensions.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 
 

+ 1 - 1
MediaBrowser.Common/Extensions/SplitStringExtensions.cs

@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
  */
  */
-#nullable enable
+
 #pragma warning disable CS1591
 #pragma warning disable CS1591
 #pragma warning disable CA1034
 #pragma warning disable CA1034
 using System;
 using System;

+ 0 - 2
MediaBrowser.Common/Extensions/StreamExtensions.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;

+ 2 - 0
MediaBrowser.Common/IApplicationHost.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Reflection;
 using System.Reflection;

+ 3 - 54
MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs

@@ -9,67 +9,16 @@ namespace MediaBrowser.Common.Json.Converters
     /// Convert comma delimited string to array of type.
     /// Convert comma delimited string to array of type.
     /// </summary>
     /// </summary>
     /// <typeparam name="T">Type to convert to.</typeparam>
     /// <typeparam name="T">Type to convert to.</typeparam>
-    public class JsonCommaDelimitedArrayConverter<T> : JsonConverter<T[]>
+    public sealed class JsonCommaDelimitedArrayConverter<T> : JsonDelimitedArrayConverter<T>
     {
     {
-        private readonly TypeConverter _typeConverter;
-
         /// <summary>
         /// <summary>
         /// Initializes a new instance of the <see cref="JsonCommaDelimitedArrayConverter{T}"/> class.
         /// Initializes a new instance of the <see cref="JsonCommaDelimitedArrayConverter{T}"/> class.
         /// </summary>
         /// </summary>
-        public JsonCommaDelimitedArrayConverter()
+        public JsonCommaDelimitedArrayConverter() : base()
         {
         {
-            _typeConverter = TypeDescriptor.GetConverter(typeof(T));
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public override T[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
-        {
-            if (reader.TokenType == JsonTokenType.String)
-            {
-                var stringEntries = reader.GetString().Split(',', StringSplitOptions.RemoveEmptyEntries);
-                if (stringEntries.Length == 0)
-                {
-                    return Array.Empty<T>();
-                }
-
-                var parsedValues = new object[stringEntries.Length];
-                var convertedCount = 0;
-                for (var i = 0; i < stringEntries.Length; i++)
-                {
-                    try
-                    {
-                        parsedValues[i] = _typeConverter.ConvertFrom(stringEntries[i].Trim());
-                        convertedCount++;
-                    }
-                    catch (FormatException)
-                    {
-                        // TODO log when upgraded to .Net6
-                        // https://github.com/dotnet/runtime/issues/42975
-                        // _logger.LogDebug(e, "Error converting value.");
-                    }
-                }
-
-                var typedValues = new T[convertedCount];
-                var typedValueIndex = 0;
-                for (var i = 0; i < stringEntries.Length; i++)
-                {
-                    if (parsedValues[i] != null)
-                    {
-                        typedValues.SetValue(parsedValues[i], typedValueIndex);
-                        typedValueIndex++;
-                    }
-                }
-
-                return typedValues;
-            }
-
-            return JsonSerializer.Deserialize<T[]>(ref reader, options);
-        }
-
-        /// <inheritdoc />
-        public override void Write(Utf8JsonWriter writer, T[] value, JsonSerializerOptions options)
-        {
-            throw new NotImplementedException();
-        }
+        protected override char Delimiter => ',';
     }
     }
 }
 }

+ 2 - 2
MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverterFactory.cs

@@ -19,10 +19,10 @@ namespace MediaBrowser.Common.Json.Converters
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
+        public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
         {
         {
             var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
             var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
-            return (JsonConverter)Activator.CreateInstance(typeof(JsonCommaDelimitedArrayConverter<>).MakeGenericType(structType));
+            return (JsonConverter?)Activator.CreateInstance(typeof(JsonCommaDelimitedArrayConverter<>).MakeGenericType(structType));
         }
         }
     }
     }
 }
 }

+ 81 - 0
MediaBrowser.Common/Json/Converters/JsonDelimitedArrayConverter.cs

@@ -0,0 +1,81 @@
+using System;
+using System.ComponentModel;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace MediaBrowser.Common.Json.Converters
+{
+    /// <summary>
+    /// Convert delimited string to array of type.
+    /// </summary>
+    /// <typeparam name="T">Type to convert to.</typeparam>
+    public abstract class JsonDelimitedArrayConverter<T> : JsonConverter<T[]?>
+    {
+        private readonly TypeConverter _typeConverter;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="JsonDelimitedArrayConverter{T}"/> class.
+        /// </summary>
+        protected JsonDelimitedArrayConverter()
+        {
+            _typeConverter = TypeDescriptor.GetConverter(typeof(T));
+        }
+
+        /// <summary>
+        /// Gets the array delimiter.
+        /// </summary>
+        protected virtual char Delimiter { get; }
+
+        /// <inheritdoc />
+        public override T[]? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        {
+            if (reader.TokenType == JsonTokenType.String)
+            {
+                // GetString can't return null here because we already handled it above
+                var stringEntries = reader.GetString()?.Split(Delimiter, StringSplitOptions.RemoveEmptyEntries);
+                if (stringEntries == null || stringEntries.Length == 0)
+                {
+                    return Array.Empty<T>();
+                }
+
+                var parsedValues = new object[stringEntries.Length];
+                var convertedCount = 0;
+                for (var i = 0; i < stringEntries.Length; i++)
+                {
+                    try
+                    {
+                        parsedValues[i] = _typeConverter.ConvertFrom(stringEntries[i].Trim());
+                        convertedCount++;
+                    }
+                    catch (FormatException)
+                    {
+                        // TODO log when upgraded to .Net6
+                        // https://github.com/dotnet/runtime/issues/42975
+                        // _logger.LogDebug(e, "Error converting value.");
+                    }
+                }
+
+                var typedValues = new T[convertedCount];
+                var typedValueIndex = 0;
+                for (var i = 0; i < stringEntries.Length; i++)
+                {
+                    if (parsedValues[i] != null)
+                    {
+                        typedValues.SetValue(parsedValues[i], typedValueIndex);
+                        typedValueIndex++;
+                    }
+                }
+
+                return typedValues;
+            }
+
+            return JsonSerializer.Deserialize<T[]>(ref reader, options);
+        }
+
+        /// <inheritdoc />
+        public override void Write(Utf8JsonWriter writer, T[]? value, JsonSerializerOptions options)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 3 - 3
MediaBrowser.Common/Json/Converters/JsonNullableStructConverterFactory.cs

@@ -18,10 +18,10 @@ namespace MediaBrowser.Common.Json.Converters
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
+        public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
         {
         {
             var structType = typeToConvert.GenericTypeArguments[0];
             var structType = typeToConvert.GenericTypeArguments[0];
-            return (JsonConverter)Activator.CreateInstance(typeof(JsonNullableStructConverter<>).MakeGenericType(structType));
+            return (JsonConverter?)Activator.CreateInstance(typeof(JsonNullableStructConverter<>).MakeGenericType(structType));
         }
         }
     }
     }
-}
+}

+ 12 - 6
MediaBrowser.Common/Json/Converters/JsonOmdbNotAvailableStringConverter.cs

@@ -7,15 +7,21 @@ namespace MediaBrowser.Common.Json.Converters
     /// <summary>
     /// <summary>
     /// Converts a string <c>N/A</c> to <c>string.Empty</c>.
     /// Converts a string <c>N/A</c> to <c>string.Empty</c>.
     /// </summary>
     /// </summary>
-    public class JsonOmdbNotAvailableStringConverter : JsonConverter<string>
+    public class JsonOmdbNotAvailableStringConverter : JsonConverter<string?>
     {
     {
         /// <inheritdoc />
         /// <inheritdoc />
-        public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
         {
         {
+            if (reader.TokenType == JsonTokenType.Null)
+            {
+                return null;
+            }
+
             if (reader.TokenType == JsonTokenType.String)
             if (reader.TokenType == JsonTokenType.String)
             {
             {
-                var str = reader.GetString();
-                if (str != null && str.Equals("N/A", StringComparison.OrdinalIgnoreCase))
+                // GetString can't return null here because we already handled it above
+                var str = reader.GetString()!;
+                if (str.Equals("N/A", StringComparison.OrdinalIgnoreCase))
                 {
                 {
                     return null;
                     return null;
                 }
                 }
@@ -23,11 +29,11 @@ namespace MediaBrowser.Common.Json.Converters
                 return str;
                 return str;
             }
             }
 
 
-            return JsonSerializer.Deserialize<string>(ref reader, options);
+            return JsonSerializer.Deserialize<string?>(ref reader, options);
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
+        public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options)
         {
         {
             writer.WriteStringValue(value);
             writer.WriteStringValue(value);
         }
         }

+ 3 - 54
MediaBrowser.Common/Json/Converters/JsonPipeDelimitedArrayConverter.cs

@@ -9,67 +9,16 @@ namespace MediaBrowser.Common.Json.Converters
     /// Convert Pipe delimited string to array of type.
     /// Convert Pipe delimited string to array of type.
     /// </summary>
     /// </summary>
     /// <typeparam name="T">Type to convert to.</typeparam>
     /// <typeparam name="T">Type to convert to.</typeparam>
-    public class JsonPipeDelimitedArrayConverter<T> : JsonConverter<T[]>
+    public sealed class JsonPipeDelimitedArrayConverter<T> : JsonDelimitedArrayConverter<T>
     {
     {
-        private readonly TypeConverter _typeConverter;
-
         /// <summary>
         /// <summary>
         /// Initializes a new instance of the <see cref="JsonPipeDelimitedArrayConverter{T}"/> class.
         /// Initializes a new instance of the <see cref="JsonPipeDelimitedArrayConverter{T}"/> class.
         /// </summary>
         /// </summary>
-        public JsonPipeDelimitedArrayConverter()
+        public JsonPipeDelimitedArrayConverter() : base()
         {
         {
-            _typeConverter = TypeDescriptor.GetConverter(typeof(T));
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public override T[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
-        {
-            if (reader.TokenType == JsonTokenType.String)
-            {
-                var stringEntries = reader.GetString()?.Split('|', StringSplitOptions.RemoveEmptyEntries);
-                if (stringEntries == null || stringEntries.Length == 0)
-                {
-                    return Array.Empty<T>();
-                }
-
-                var parsedValues = new object[stringEntries.Length];
-                var convertedCount = 0;
-                for (var i = 0; i < stringEntries.Length; i++)
-                {
-                    try
-                    {
-                        parsedValues[i] = _typeConverter.ConvertFrom(stringEntries[i].Trim());
-                        convertedCount++;
-                    }
-                    catch (FormatException)
-                    {
-                        // TODO log when upgraded to .Net6
-                        // https://github.com/dotnet/runtime/issues/42975
-                        // _logger.LogDebug(e, "Error converting value.");
-                    }
-                }
-
-                var typedValues = new T[convertedCount];
-                var typedValueIndex = 0;
-                for (var i = 0; i < stringEntries.Length; i++)
-                {
-                    if (parsedValues[i] != null)
-                    {
-                        typedValues.SetValue(parsedValues[i], typedValueIndex);
-                        typedValueIndex++;
-                    }
-                }
-
-                return typedValues;
-            }
-
-            return JsonSerializer.Deserialize<T[]>(ref reader, options);
-        }
-
-        /// <inheritdoc />
-        public override void Write(Utf8JsonWriter writer, T[] value, JsonSerializerOptions options)
-        {
-            throw new NotImplementedException();
-        }
+        protected override char Delimiter => '|';
     }
     }
 }
 }

+ 2 - 2
MediaBrowser.Common/Json/Converters/JsonPipeDelimitedArrayConverterFactory.cs

@@ -19,10 +19,10 @@ namespace MediaBrowser.Common.Json.Converters
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
+        public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
         {
         {
             var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
             var structType = typeToConvert.GetElementType() ?? typeToConvert.GenericTypeArguments[0];
-            return (JsonConverter)Activator.CreateInstance(typeof(JsonPipeDelimitedArrayConverter<>).MakeGenericType(structType));
+            return (JsonConverter?)Activator.CreateInstance(typeof(JsonPipeDelimitedArrayConverter<>).MakeGenericType(structType));
         }
         }
     }
     }
 }
 }

+ 4 - 4
MediaBrowser.Common/Json/Converters/JsonStringConverter.cs

@@ -9,10 +9,10 @@ namespace MediaBrowser.Common.Json.Converters
     /// <summary>
     /// <summary>
     /// Converter to allow the serializer to read strings.
     /// Converter to allow the serializer to read strings.
     /// </summary>
     /// </summary>
-    public class JsonStringConverter : JsonConverter<string>
+    public class JsonStringConverter : JsonConverter<string?>
     {
     {
         /// <inheritdoc />
         /// <inheritdoc />
-        public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
         {
         {
             return reader.TokenType switch
             return reader.TokenType switch
             {
             {
@@ -23,7 +23,7 @@ namespace MediaBrowser.Common.Json.Converters
         }
         }
 
 
         /// <inheritdoc />
         /// <inheritdoc />
-        public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
+        public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options)
         {
         {
             writer.WriteStringValue(value);
             writer.WriteStringValue(value);
         }
         }
@@ -36,4 +36,4 @@ namespace MediaBrowser.Common.Json.Converters
             return Encoding.UTF8.GetString(utf8Bytes);
             return Encoding.UTF8.GetString(utf8Bytes);
         }
         }
     }
     }
-}
+}

+ 1 - 1
MediaBrowser.Common/Json/Converters/JsonVersionConverter.cs

@@ -14,7 +14,7 @@ namespace MediaBrowser.Common.Json.Converters
     {
     {
         /// <inheritdoc />
         /// <inheritdoc />
         public override Version Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
         public override Version Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
-            => new Version(reader.GetString());
+            => new Version(reader.GetString()!); // Will throw ArgumentNullException on null
 
 
         /// <inheritdoc />
         /// <inheritdoc />
         public override void Write(Utf8JsonWriter writer, Version value, JsonSerializerOptions options)
         public override void Write(Utf8JsonWriter writer, Version value, JsonSerializerOptions options)

+ 1 - 0
MediaBrowser.Common/MediaBrowser.Common.csproj

@@ -33,6 +33,7 @@
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+    <Nullable>enable</Nullable>
     <AnalysisMode>AllEnabledByDefault</AnalysisMode>
     <AnalysisMode>AllEnabledByDefault</AnalysisMode>
     <CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
     <CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>
     <PublishRepositoryUrl>true</PublishRepositoryUrl>

+ 0 - 1
MediaBrowser.Common/Net/INetworkManager.cs

@@ -1,4 +1,3 @@
-#nullable enable
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;

+ 0 - 1
MediaBrowser.Common/Net/IPHost.cs

@@ -1,4 +1,3 @@
-#nullable enable
 using System;
 using System;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Linq;
 using System.Linq;

+ 0 - 1
MediaBrowser.Common/Net/IPNetAddress.cs

@@ -1,4 +1,3 @@
-#nullable enable
 using System;
 using System;
 using System.Net;
 using System.Net;
 using System.Net.Sockets;
 using System.Net.Sockets;

+ 0 - 1
MediaBrowser.Common/Net/IPObject.cs

@@ -1,4 +1,3 @@
-#nullable enable
 using System;
 using System;
 using System.Net;
 using System.Net;
 using System.Net.Sockets;
 using System.Net.Sockets;

+ 2 - 0
MediaBrowser.Common/Plugins/BasePlugin.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System;
 using System;
 using System.IO;
 using System.IO;
 using System.Reflection;
 using System.Reflection;

+ 2 - 0
MediaBrowser.Common/Plugins/BasePluginOfT.cs

@@ -1,4 +1,6 @@
+#nullable disable
 #pragma warning disable SA1649 // File name should match first type name
 #pragma warning disable SA1649 // File name should match first type name
+
 using System;
 using System;
 using System.IO;
 using System.IO;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;

+ 2 - 0
MediaBrowser.Common/Plugins/IPlugin.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System;
 using System;
 using MediaBrowser.Model.Plugins;
 using MediaBrowser.Model.Plugins;
 
 

+ 0 - 2
MediaBrowser.Common/Plugins/IPluginManager.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Reflection;
 using System.Reflection;

+ 0 - 1
MediaBrowser.Common/Plugins/LocalPlugin.cs

@@ -1,4 +1,3 @@
-#nullable enable
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using MediaBrowser.Model.Plugins;
 using MediaBrowser.Model.Plugins;

+ 0 - 2
MediaBrowser.Common/Plugins/PluginManifest.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 using System.Text.Json.Serialization;
 using System.Text.Json.Serialization;
 using MediaBrowser.Model.Plugins;
 using MediaBrowser.Model.Plugins;

+ 2 - 2
MediaBrowser.Common/Progress/ActionableProgress.cs

@@ -14,9 +14,9 @@ namespace MediaBrowser.Common.Progress
         /// <summary>
         /// <summary>
         /// The _actions.
         /// The _actions.
         /// </summary>
         /// </summary>
-        private Action<T> _action;
+        private Action<T>? _action;
 
 
-        public event EventHandler<T> ProgressChanged;
+        public event EventHandler<T>? ProgressChanged;
 
 
         /// <summary>
         /// <summary>
         /// Registers the action.
         /// Registers the action.

+ 1 - 1
MediaBrowser.Common/Progress/SimpleProgress.cs

@@ -7,7 +7,7 @@ namespace MediaBrowser.Common.Progress
 {
 {
     public class SimpleProgress<T> : IProgress<T>
     public class SimpleProgress<T> : IProgress<T>
     {
     {
-        public event EventHandler<T> ProgressChanged;
+        public event EventHandler<T>? ProgressChanged;
 
 
         public void Report(T value)
         public void Report(T value)
         {
         {

+ 1 - 3
MediaBrowser.Common/Providers/ProviderIdParsers.cs

@@ -1,6 +1,4 @@
-#nullable enable
-
-using System;
+using System;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.CodeAnalysis;
 
 
 namespace MediaBrowser.Common.Providers
 namespace MediaBrowser.Common.Providers

+ 0 - 2
MediaBrowser.Common/Updates/IInstallationManager.cs

@@ -1,5 +1,3 @@
-#nullable enable
-
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading;

+ 2 - 0
MediaBrowser.Common/Updates/InstallationEventArgs.cs

@@ -1,3 +1,5 @@
+#nullable disable
+
 using System;
 using System;
 using MediaBrowser.Model.Updates;
 using MediaBrowser.Model.Updates;
 
 

+ 1 - 0
MediaBrowser.Common/Updates/InstallationFailedEventArgs.cs

@@ -1,3 +1,4 @@
+#nullable disable
 #pragma warning disable CS1591
 #pragma warning disable CS1591
 
 
 using System;
 using System;