From 1ebdfa149a27768d6ead01dfed7feae1cdd1ca94 Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Sun, 13 Oct 2019 14:21:15 -0400 Subject: [PATCH] Fix NullReferenceException in ToolManager.IsAvailable and remove unnecessary try/catch. --- BizHawk.Client.EmuHawk/ToolAttribute.cs | 11 ++++++----- BizHawk.Client.EmuHawk/tools/ToolManager.cs | 8 ++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/BizHawk.Client.EmuHawk/ToolAttribute.cs b/BizHawk.Client.EmuHawk/ToolAttribute.cs index 721fa0cf48..53a2f837da 100644 --- a/BizHawk.Client.EmuHawk/ToolAttribute.cs +++ b/BizHawk.Client.EmuHawk/ToolAttribute.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace BizHawk.Client.EmuHawk { @@ -9,14 +10,14 @@ namespace BizHawk.Client.EmuHawk public ToolAttribute(bool released, string[] supportedSystems, string[] unsupportedCores = null) { Released = released; - SupportedSystems = supportedSystems; - UnsupportedCores = unsupportedCores; + SupportedSystems = supportedSystems ?? Enumerable.Empty(); + UnsupportedCores = unsupportedCores ?? Enumerable.Empty(); } - public bool Released { get; private set; } + public bool Released { get; } - public IEnumerable SupportedSystems { get; private set; } + public IEnumerable SupportedSystems { get; } - public IEnumerable UnsupportedCores { get; private set; } + public IEnumerable UnsupportedCores { get; } } } diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index fef10a6b4b..e8bc2338ae 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -752,12 +752,8 @@ namespace BizHawk.Client.EmuHawk return false; } - ToolAttribute attr; - try - { - attr = tool.GetCustomAttributes(false).OfType().Single(); - } - catch (InvalidOperationException e) + ToolAttribute attr = tool.GetCustomAttributes(false).OfType().SingleOrDefault(); + if (attr == null) { return true; // no ToolAttribute on given type -> assumed all supported }