From 47109511859f45e053389af6c0c33b4cf3eaa6fc Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle Date: Mon, 4 Apr 2022 10:34:13 +0200 Subject: [PATCH] fix build errors --- .../Editors/UserEditorAuthorizationHelper.cs | 10 +++++----- src/Umbraco.Core/GuidUtils.cs | 7 ++++--- .../CombinedGuidsMediaPathScheme.cs | 2 +- .../Models/ContentEditing/ContentBaseSave.cs | 4 ++-- .../Models/ContentEditing/ContentItemSave.cs | 2 +- .../ContentEditing/DictionaryTranslationSave.cs | 2 +- .../Models/ContentEditing/EntityBasic.cs | 2 +- .../Models/ContentScheduleCollection.cs | 4 ++-- src/Umbraco.Core/Models/PropertyTagsExtensions.cs | 2 +- src/Umbraco.Core/Models/Template.cs | 2 +- .../Notifications/UserLockedNotification.cs | 2 +- .../PropertyEditors/ConfigurationEditor.cs | 12 +++++++++--- .../PropertyEditors/ConfigurationField.cs | 2 +- .../ConfigurationFieldAttribute.cs | 4 +++- .../Validators/DateTimeValidator.cs | 2 +- .../Validators/DecimalValidator.cs | 2 +- .../Validators/DelimitedValueValidator.cs | 2 +- .../PropertyEditors/Validators/EmailValidator.cs | 2 +- .../Validators/IntegerValidator.cs | 2 +- .../PropertyEditors/Validators/RegexValidator.cs | 4 ++-- .../Validators/RequiredValidator.cs | 4 ++-- src/Umbraco.Core/Security/ContentPermissions.cs | 6 +++--- src/Umbraco.Core/Services/ContentService.cs | 6 +++--- ...ntTypeServiceBaseOfTRepositoryTItemTService.cs | 9 +++++++-- src/Umbraco.Core/Services/DashboardService.cs | 6 +++--- src/Umbraco.Core/Services/FileService.cs | 8 ++++++-- src/Umbraco.Core/Services/ILocalizationService.cs | 2 +- src/Umbraco.Core/Services/IUserService.cs | 4 ++-- src/Umbraco.Core/Services/LocalizationService.cs | 2 +- .../Services/LocalizedTextServiceExtensions.cs | 2 +- src/Umbraco.Core/Services/UserService.cs | 15 ++++++++++----- .../Web/Mvc/PluginControllerMetadata.cs | 2 +- .../ColorPickerConfigurationEditor.cs | 4 ++-- .../ConfigurationEditorOfTConfiguration.cs | 6 +++--- .../DropDownFlexibleConfigurationEditor.cs | 4 ++-- .../EyeDropperColorPickerConfigurationEditor.cs | 6 +++--- .../PropertyEditors/LabelConfigurationEditor.cs | 4 ++-- .../MultipleTextStringConfigurationEditor.cs | 6 +++--- .../PropertyEditors/TagConfigurationEditor.cs | 8 ++++++-- .../ValueListConfigurationEditor.cs | 4 ++-- .../Controllers/MemberController.cs | 2 +- .../Controllers/UserGroupsController.cs | 7 +++++-- .../ModelBinders/MediaItemBinder.cs | 2 +- .../Extensions/EndpointRouteBuilderExtensions.cs | 6 +++--- .../Extensions/ViewDataExtensions.cs | 2 +- .../ModelsBuilderNotificationHandler.cs | 2 +- .../CombineGuidBenchmarks.cs | 2 +- .../Umbraco.Core/GuidUtilsTests.cs | 2 +- 48 files changed, 117 insertions(+), 87 deletions(-) diff --git a/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs b/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs index b2cd34875c..23fc59da24 100644 --- a/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs +++ b/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs @@ -41,7 +41,7 @@ namespace Umbraco.Cms.Core.Editors IEnumerable? startContentIds, IEnumerable? startMediaIds, IEnumerable? userGroupAliases) { - var currentIsAdmin = currentUser.IsAdmin(); + var currentIsAdmin = currentUser?.IsAdmin() ?? false; // a) A non-admin cannot save an admin @@ -67,7 +67,7 @@ namespace Umbraco.Cms.Core.Editors : startMediaIds == null || savingUser.StartMediaIds is null ? null : startMediaIds.Except(savingUser.StartMediaIds).ToArray(); - var pathResult = AuthorizePath(currentUser, changedStartContentIds, changedStartMediaIds); + var pathResult = currentUser is null ? Attempt.Fail() : AuthorizePath(currentUser, changedStartContentIds, changedStartMediaIds); if (pathResult == false) return pathResult; @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.Editors var addedGroupAliases = savingGroupAliases.Except(existingGroupAliases); // As we know the current user is not admin, it is only allowed to use groups that the user do have themselves. - var savingGroupAliasesNotAllowed = addedGroupAliases.Except(currentUser.Groups.Select(x=>x.Alias)).ToArray(); + var savingGroupAliasesNotAllowed = addedGroupAliases.Except(currentUser?.Groups.Select(x=> x.Alias) ?? Enumerable.Empty()).ToArray(); if (savingGroupAliasesNotAllowed.Any()) { return Attempt.Fail("Cannot assign the group(s) '" + string.Join(", ", savingGroupAliasesNotAllowed) + "', the current user is not part of them or admin"); @@ -106,10 +106,10 @@ namespace Umbraco.Cms.Core.Editors if (userGroupsChanged) { // d) A user cannot assign a group to another user that they do not belong to - var currentUserGroups = currentUser.Groups.Select(x => x.Alias).ToArray(); + var currentUserGroups = currentUser?.Groups.Select(x => x.Alias).ToArray(); foreach (var group in newGroups) { - if (currentUserGroups.Contains(group) == false) + if (currentUserGroups?.Contains(group) == false) { return Attempt.Fail("Cannot assign the group " + group + ", the current user is not a member"); } diff --git a/src/Umbraco.Core/GuidUtils.cs b/src/Umbraco.Core/GuidUtils.cs index 31e168966b..e6ccd6b27f 100644 --- a/src/Umbraco.Core/GuidUtils.cs +++ b/src/Umbraco.Core/GuidUtils.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core /// The seconds guid. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Guid? Combine(Guid a, Guid b) + public static Guid Combine(Guid a, Guid b) { var ad = new DecomposedGuid(a); var bd = new DecomposedGuid(b); @@ -58,12 +58,13 @@ namespace Umbraco.Cms.Core /// that is case insensitive (base-64 is case sensitive). /// Length must be 1-26, anything else becomes 26. /// - public static string ToBase32String(Guid? guid, int length = 26) + public static string ToBase32String(Guid guid, int length = 26) { + if (length <= 0 || length > 26) length = 26; - var bytes = guid?.ToByteArray(); // a Guid is 128 bits ie 16 bytes + var bytes = guid.ToByteArray(); // a Guid is 128 bits ie 16 bytes // this could be optimized by making it unsafe, // and fixing the table + bytes + chars (see Convert.ToBase64CharArray) diff --git a/src/Umbraco.Core/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs b/src/Umbraco.Core/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs index 01579adb82..5adc81276b 100644 --- a/src/Umbraco.Core/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs +++ b/src/Umbraco.Core/IO/MediaPathSchemes/CombinedGuidsMediaPathScheme.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.IO.MediaPathSchemes // for a single content cannot store two different files with the same name var combinedGuid = GuidUtils.Combine(itemGuid, propertyGuid); - var directory = HexEncoder.Encode(combinedGuid?.ToByteArray()/*'/', 2, 4*/); // could use ext to fragment path eg 12/e4/f2/... + var directory = HexEncoder.Encode(combinedGuid.ToByteArray()/*'/', 2, 4*/); // could use ext to fragment path eg 12/e4/f2/... return Path.Combine(directory, filename).Replace('\\', '/'); } diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs b/src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs index 13d3c667e9..d7f026aeab 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs @@ -36,11 +36,11 @@ namespace Umbraco.Cms.Core.Models.ContentEditing //These need explicit implementation because we are using internal models /// [IgnoreDataMember] - TPersisted IContentSave.PersistedContent { get; set; } + TPersisted IContentSave.PersistedContent { get; set; } = default!; //Non explicit internal getter so we don't need to explicitly cast in our own code [IgnoreDataMember] - public TPersisted? PersistedContent + public TPersisted PersistedContent { get => ((IContentSave)this).PersistedContent; set => ((IContentSave) this).PersistedContent = value; diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs b/src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs index acf2c5d789..fed33c52b0 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing //These need explicit implementation because we are using internal models /// [IgnoreDataMember] - IContent IContentSave.PersistedContent { get; set; } + IContent IContentSave.PersistedContent { get; set; } = null!; //Non explicit internal getter so we don't need to explicitly cast in our own code [IgnoreDataMember] diff --git a/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs b/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs index b86d6cf6e2..aa42abbf56 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// Gets or sets the translation. /// [DataMember(Name = "translation")] - public string? Translation { get; set; } + public string Translation { get; set; } = null!; /// /// Gets or sets the language id. diff --git a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs index 4921c12058..772da930e9 100644 --- a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing { public EntityBasic() { - AdditionalData = new Dictionary(); + AdditionalData = new Dictionary(); Alias = string.Empty; Path = string.Empty; } diff --git a/src/Umbraco.Core/Models/ContentScheduleCollection.cs b/src/Umbraco.Core/Models/ContentScheduleCollection.cs index 42d1b07404..12a53fd103 100644 --- a/src/Umbraco.Core/Models/ContentScheduleCollection.cs +++ b/src/Umbraco.Core/Models/ContentScheduleCollection.cs @@ -132,7 +132,7 @@ namespace Umbraco.Cms.Core.Models /// If specified, will clear all entries with dates less than or equal to the value public void Clear(string? culture, ContentScheduleAction action, DateTime? date = null) { - if (!_schedule.TryGetValue(culture, out var schedules)) + if (culture is null || !_schedule.TryGetValue(culture, out var schedules)) return; var removes = schedules.Where(x => x.Value.Action == action && (!date.HasValue || x.Value.Date <= date.Value)).ToList(); @@ -178,7 +178,7 @@ namespace Umbraco.Cms.Core.Models /// public IEnumerable GetSchedule(string? culture, ContentScheduleAction? action = null) { - if (_schedule.TryGetValue(culture, out var changes)) + if (culture is not null && _schedule.TryGetValue(culture, out var changes)) return action == null ? changes.Values : changes.Values.Where(x => x.Action == action.Value); return Enumerable.Empty(); } diff --git a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs index 75b0ea3cb3..7bd3a49baf 100644 --- a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs +++ b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs @@ -203,7 +203,7 @@ namespace Umbraco.Extensions // assumes that parameters are consistent with the datatype configuration // value can be an enumeration of string, or a serialized value using storageType format - private static void SetTagsValue(IProperty property, object value, TagsStorageType storageType, IJsonSerializer serializer, char delimiter, string culture) + private static void SetTagsValue(IProperty property, object? value, TagsStorageType storageType, IJsonSerializer serializer, char delimiter, string? culture) { if (value == null) value = Enumerable.Empty(); diff --git a/src/Umbraco.Core/Models/Template.cs b/src/Umbraco.Core/Models/Template.cs index 1ba6b4a5ff..7efccf1e7d 100644 --- a/src/Umbraco.Core/Models/Template.cs +++ b/src/Umbraco.Core/Models/Template.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Models private string? _masterTemplateAlias; private Lazy? _masterTemplateId; - public Template(IShortStringHelper shortStringHelper, string? name, string alias) + public Template(IShortStringHelper shortStringHelper, string? name, string? alias) : this(shortStringHelper, name, alias, null) { } diff --git a/src/Umbraco.Core/Notifications/UserLockedNotification.cs b/src/Umbraco.Core/Notifications/UserLockedNotification.cs index 492296b7a2..b7485d9852 100644 --- a/src/Umbraco.Core/Notifications/UserLockedNotification.cs +++ b/src/Umbraco.Core/Notifications/UserLockedNotification.cs @@ -2,7 +2,7 @@ namespace Umbraco.Cms.Core.Notifications { public class UserLockedNotification : UserNotification { - public UserLockedNotification(string ipAddress, string affectedUserId, string performingUserId) : base(ipAddress, affectedUserId, performingUserId) + public UserLockedNotification(string ipAddress, string? affectedUserId, string performingUserId) : base(ipAddress, affectedUserId, performingUserId) { } } diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs index ef441d3965..89d19c5115 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationEditor.cs @@ -86,17 +86,23 @@ namespace Umbraco.Cms.Core.PropertyEditors : configurationEditorJsonSerializer.Deserialize>(configurationJson)!; /// - public virtual object? FromConfigurationEditor(IDictionary editorValues, object configuration) + public virtual object? FromConfigurationEditor(IDictionary? editorValues, object? configuration) { // by default, return the posted dictionary // but only keep entries that have a non-null/empty value // rest will fall back to default during ToConfigurationEditor() - var keys = editorValues.Where(x => + var keys = editorValues?.Where(x => x.Value == null || x.Value is string stringValue && string.IsNullOrWhiteSpace(stringValue)) .Select(x => x.Key).ToList(); - foreach (var key in keys) editorValues.Remove(key); + if (keys is not null) + { + foreach (var key in keys) + { + editorValues?.Remove(key); + } + } return editorValues; } diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs index 5f860445a0..0e679f9dc1 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// Gets or sets the key of the field. /// [DataMember(Name = "key", IsRequired = true)] - public string? Key { get; set; } + public string Key { get; set; } = null!; /// /// Gets or sets the name of the field. diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs index 012003db8a..79e9655e25 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs @@ -17,6 +17,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public ConfigurationFieldAttribute(Type type) { Type = type; + Key = string.Empty; } /// @@ -55,6 +56,7 @@ namespace Umbraco.Cms.Core.PropertyEditors Name = name; View = view; + Key = string.Empty; } /// @@ -62,7 +64,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// When null or empty, the should derive a key /// from the name of the property marked with this attribute. - public string? Key { get; } + public string Key { get; } /// /// Gets the friendly name of the field. diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs index 6404e54dfa..7c15a418d8 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs @@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators /// public class DateTimeValidator : IValueValidator { - public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { //don't validate if empty if (value == null || value.ToString().IsNullOrWhiteSpace()) diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs index cfcec9a050..1fb2486e45 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Decimal"; /// - public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { if (value == null || value.ToString() == string.Empty) yield break; diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs index 4e6799c443..8e93e5189e 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators /// - public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { // TODO: localize these! if (value != null) diff --git a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs index cfba0fab72..0db537ede5 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Email"; /// - public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { var asString = value == null ? "" : value.ToString(); diff --git a/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs index a79088b65b..351d0de82d 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Integer"; /// - public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { if (value != null && value.ToString() != string.Empty) { diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs index 380efb9238..ead85c30e4 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs @@ -60,7 +60,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators } /// - public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { if (_regex == null) { @@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators } /// - public IEnumerable ValidateFormat(object? value, string valueType, string format) + public IEnumerable ValidateFormat(object? value, string? valueType, string format) { if (format == null) throw new ArgumentNullException(nameof(format)); if (string.IsNullOrWhiteSpace(format)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(format)); diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs index ae12a3641e..050ba5a388 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs @@ -22,13 +22,13 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Required"; /// - public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { return ValidateRequired(value, valueType); } /// - public IEnumerable ValidateRequired(object? value, string valueType) + public IEnumerable ValidateRequired(object? value, string? valueType) { if (value == null) { diff --git a/src/Umbraco.Core/Security/ContentPermissions.cs b/src/Umbraco.Core/Security/ContentPermissions.cs index 3574471813..73f9f4ccef 100644 --- a/src/Umbraco.Core/Security/ContentPermissions.cs +++ b/src/Umbraco.Core/Security/ContentPermissions.cs @@ -261,7 +261,7 @@ namespace Umbraco.Cms.Core.Security } //is it self? - var self = startNodePaths.Any(x => x == path); + var self = startNodePaths?.Any(x => x == path) ?? false; if (self) { hasPathAccess = true; @@ -269,7 +269,7 @@ namespace Umbraco.Cms.Core.Security } //is it ancestor? - var ancestor = startNodePaths.Any(x => x.StartsWith(path)); + var ancestor = startNodePaths?.Any(x => x.StartsWith(path)) ?? false; if (ancestor) { //hasPathAccess = false; @@ -277,7 +277,7 @@ namespace Umbraco.Cms.Core.Security } //is it descendant? - var descendant = startNodePaths.Any(x => path.StartsWith(x)); + var descendant = startNodePaths?.Any(x => path.StartsWith(x)) ?? false; if (descendant) { hasPathAccess = true; diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 9d5340f55d..11420df048 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -2850,12 +2850,12 @@ namespace Umbraco.Cms.Core.Services /// /// /// Result indicating what action was taken when handling the command. - public OperationResult Sort(IEnumerable ids, int userId = Constants.Security.SuperUserId) + public OperationResult Sort(IEnumerable? ids, int userId = Constants.Security.SuperUserId) { EventMessages evtMsgs = EventMessagesFactory.Get(); - var idsA = ids.ToArray(); - if (idsA.Length == 0) + var idsA = ids?.ToArray(); + if (idsA is null || idsA.Length == 0) { return new OperationResult(OperationResultType.NoOperation, evtMsgs); } diff --git a/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs b/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs index 36e9ac26c5..9a38b55b83 100644 --- a/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs +++ b/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs @@ -76,7 +76,7 @@ namespace Umbraco.Cms.Core.Services using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); - ValidateLocked(compo); + ValidateLocked(compo!); } return Attempt.Succeed(); } @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.Services } } - protected void ValidateLocked(TItem? compositionContentType) + protected void ValidateLocked(TItem compositionContentType) { // performs business-level validation of the composition // should ensure that it is absolutely safe to save the composition @@ -299,6 +299,11 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAll(IEnumerable? ids) { + if (ids is null) + { + return Enumerable.Empty(); + } + using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); diff --git a/src/Umbraco.Core/Services/DashboardService.cs b/src/Umbraco.Core/Services/DashboardService.cs index b5e4755122..203ce64984 100644 --- a/src/Umbraco.Core/Services/DashboardService.cs +++ b/src/Umbraco.Core/Services/DashboardService.cs @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.Services foreach (var dashboard in _dashboardCollection.Where(x => x.Sections.InvariantContains(section))) { // validate access - if (!CheckUserAccessByRules(currentUser, _sectionService, dashboard.AccessRules)) + if (currentUser is null || !CheckUserAccessByRules(currentUser, _sectionService, dashboard.AccessRules)) continue; if (dashboard.View?.InvariantEndsWith(".ascx") ?? false) @@ -61,9 +61,9 @@ namespace Umbraco.Cms.Core.Services return _sectionService.GetSections().ToDictionary(x => x.Alias, x => GetDashboards(x.Alias, currentUser)); } - private bool CheckUserAccessByRules(IUser? user, ISectionService sectionService, IEnumerable rules) + private bool CheckUserAccessByRules(IUser user, ISectionService sectionService, IEnumerable rules) { - if (user?.Id == Constants.Security.SuperUserId) + if (user.Id == Constants.Security.SuperUserId) return true; var (denyRules, grantRules, grantBySectionRules) = GroupRules(rules); diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index c6a5e5f8e4..009059916a 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -201,8 +201,12 @@ namespace Umbraco.Cms.Core.Services } /// - public void SaveScript(IScript? script, int? userId = Constants.Security.SuperUserId) + public void SaveScript(IScript? script, int? userId) { + if (userId is null) + { + userId = Constants.Security.SuperUserId; + } if (script is null) { return; @@ -316,7 +320,7 @@ namespace Umbraco.Cms.Core.Services /// /// The template created /// - public Attempt?> CreateTemplateForContentType(string contentTypeAlias, string contentTypeName, int userId = Constants.Security.SuperUserId) + public Attempt?> CreateTemplateForContentType(string contentTypeAlias, string? contentTypeName, int userId = Constants.Security.SuperUserId) { var template = new Template(_shortStringHelper, contentTypeName, //NOTE: We are NOT passing in the content type alias here, we want to use it's name since we don't diff --git a/src/Umbraco.Core/Services/ILocalizationService.cs b/src/Umbraco.Core/Services/ILocalizationService.cs index b478aed5bd..f68214cfc3 100644 --- a/src/Umbraco.Core/Services/ILocalizationService.cs +++ b/src/Umbraco.Core/Services/ILocalizationService.cs @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Services /// /// - void AddOrUpdateDictionaryValue(IDictionaryItem item, ILanguage? language, string? value); + void AddOrUpdateDictionaryValue(IDictionaryItem item, ILanguage? language, string value); /// /// Creates and saves a new dictionary item and assigns a value to all languages if defaultValue is specified. diff --git a/src/Umbraco.Core/Services/IUserService.cs b/src/Umbraco.Core/Services/IUserService.cs index 0842d47b36..9a63fcf0ad 100644 --- a/src/Umbraco.Core/Services/IUserService.cs +++ b/src/Umbraco.Core/Services/IUserService.cs @@ -150,7 +150,7 @@ namespace Umbraco.Cms.Core.Services /// /// Specifying nothing will return all permissions for all nodes /// An enumerable list of - EntityPermissionCollection GetPermissions(IUserGroup[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds); + EntityPermissionCollection GetPermissions(IUserGroup?[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds); /// /// Gets the implicit/inherited permissions for the user for the given path @@ -243,7 +243,7 @@ namespace Umbraco.Cms.Core.Services /// If null than no changes are made to the users who are assigned to this group, however if a value is passed in /// than all users will be removed from this group and only these users will be added /// - void Save(IUserGroup? userGroup, int[]? userIds = null); + void Save(IUserGroup userGroup, int[]? userIds = null); /// /// Deletes a UserGroup diff --git a/src/Umbraco.Core/Services/LocalizationService.cs b/src/Umbraco.Core/Services/LocalizationService.cs index efccd5ddf4..4b44ee7d9a 100644 --- a/src/Umbraco.Core/Services/LocalizationService.cs +++ b/src/Umbraco.Core/Services/LocalizationService.cs @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.Services /// /// This does not save the item, that needs to be done explicitly /// - public void AddOrUpdateDictionaryValue(IDictionaryItem item, ILanguage? language, string? value) + public void AddOrUpdateDictionaryValue(IDictionaryItem item, ILanguage? language, string value) { if (item == null) throw new ArgumentNullException(nameof(item)); if (language == null) throw new ArgumentNullException(nameof(language)); diff --git a/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs b/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs index 19ee3a4239..8a9559f7bc 100644 --- a/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs +++ b/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs @@ -51,7 +51,7 @@ namespace Umbraco.Extensions /// /// /// - internal static IDictionary? ConvertToDictionaryVars(string?[] variables) + internal static IDictionary? ConvertToDictionaryVars(string?[]? variables) { if (variables == null) return null; if (variables.Any() == false) return null; diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 1cf1f9ede2..e280fa98e8 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -192,8 +192,13 @@ namespace Umbraco.Cms.Core.Services /// /// Username to use for retrieval /// - public IUser? GetByUsername(string username) + public IUser? GetByUsername(string? username) { + if (username is null) + { + return null; + } + using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { try @@ -813,7 +818,7 @@ namespace Umbraco.Cms.Core.Services /// than all users will be removed from this group and only these users will be added /// /// Default is True otherwise set to False to not raise events - public void Save(IUserGroup? userGroup, int[]? userIds = null) + public void Save(IUserGroup userGroup, int[]? userIds = null) { var evtMsgs = EventMessagesFactory.Get(); @@ -826,7 +831,7 @@ namespace Umbraco.Cms.Core.Services if (userIds != null) { - var groupUsers = userGroup?.HasIdentity ?? false ? _userRepository.GetAllInGroup(userGroup.Id).ToArray() : empty; + var groupUsers = userGroup.HasIdentity ? _userRepository.GetAllInGroup(userGroup.Id).ToArray() : empty; var xGroupUsers = groupUsers.ToDictionary(x => x.Id, x => x); var groupIds = groupUsers.Select(x => x.Id).ToArray(); var addedUserIds = userIds.Except(groupIds); @@ -951,12 +956,12 @@ namespace Umbraco.Cms.Core.Services /// /// Specifying nothing will return all permissions for all nodes /// An enumerable list of - public EntityPermissionCollection GetPermissions(IUserGroup[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds) + public EntityPermissionCollection GetPermissions(IUserGroup?[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds) { if (groups == null) throw new ArgumentNullException(nameof(groups)); using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - return _userGroupRepository.GetPermissions(groups.Select(x => x.ToReadOnlyGroup()).ToArray(), fallbackToDefaultPermissions, nodeIds); + return _userGroupRepository.GetPermissions(groups.WhereNotNull().Select(x => x.ToReadOnlyGroup()).ToArray(), fallbackToDefaultPermissions, nodeIds); } } /// diff --git a/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs b/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs index 44bf0e3c3c..efc162a9a3 100644 --- a/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs +++ b/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Web.Mvc /// public class PluginControllerMetadata { - public Type? ControllerType { get; set; } + public Type ControllerType { get; set; } = null!; public string? ControllerName { get; set; } public string? ControllerNamespace { get; set; } public string? AreaName { get; set; } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs index b143ecded9..9f5aa14949 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs @@ -105,11 +105,11 @@ namespace Umbraco.Cms.Core.PropertyEditors // send: { "items": { "": { "value": "", "label": " /// The configuration object posted by the editor. /// The current configuration object. - public virtual TConfiguration? FromConfigurationEditor(IDictionary editorValues, TConfiguration? configuration) + public virtual TConfiguration? FromConfigurationEditor(IDictionary? editorValues, TConfiguration? configuration) { // note - editorValue contains a mix of CLR types (string, int...) and JToken // turning everything back into a JToken... might not be fastest but is simplest @@ -148,7 +148,7 @@ namespace Umbraco.Cms.Core.PropertyEditors // field only, JsonPropertyAttribute is ignored here // only keep fields that have a non-null/empty value // rest will fall back to default during ToObject() - if (editorValues.TryGetValue(field.Key!, out var value) && value != null && (!(value is string stringValue) || !string.IsNullOrWhiteSpace(stringValue))) + if (editorValues is not null && editorValues.TryGetValue(field.Key!, out var value) && value != null && (!(value is string stringValue) || !string.IsNullOrWhiteSpace(stringValue))) { if (value is JToken jtoken) { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs index cd6cb8d277..eb12ebfaa5 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs @@ -21,11 +21,11 @@ namespace Umbraco.Cms.Core.PropertyEditors items.Validators.Add(new ValueListUniqueValueValidator()); } - public override DropDownFlexibleConfiguration FromConfigurationEditor(IDictionary editorValues, DropDownFlexibleConfiguration? configuration) + public override DropDownFlexibleConfiguration FromConfigurationEditor(IDictionary? editorValues, DropDownFlexibleConfiguration? configuration) { var output = new DropDownFlexibleConfiguration(); - if (!editorValues.TryGetValue("items", out var jjj) || !(jjj is JArray jItems)) + if (editorValues is null || !editorValues.TryGetValue("items", out var jjj) || !(jjj is JArray jItems)) return output; // oops // handle multiple diff --git a/src/Umbraco.Infrastructure/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs index 6ee431ca75..34e3354367 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs @@ -23,19 +23,19 @@ namespace Umbraco.Cms.Core.PropertyEditors } /// - public override EyeDropperColorPickerConfiguration FromConfigurationEditor(IDictionary editorValues, EyeDropperColorPickerConfiguration? configuration) + public override EyeDropperColorPickerConfiguration FromConfigurationEditor(IDictionary? editorValues, EyeDropperColorPickerConfiguration? configuration) { var showAlpha = true; var showPalette = true; - if (editorValues.TryGetValue("showAlpha", out var alpha)) + if (editorValues is not null && editorValues.TryGetValue("showAlpha", out var alpha)) { var attempt = alpha.TryConvertTo(); if (attempt.Success) showAlpha = attempt.Result; } - if (editorValues.TryGetValue("showPalette", out var palette)) + if (editorValues is not null && editorValues.TryGetValue("showPalette", out var palette)) { var attempt = palette.TryConvertTo(); if (attempt.Success) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/LabelConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/LabelConfigurationEditor.cs index 72608885a0..c34a1451d4 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/LabelConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/LabelConfigurationEditor.cs @@ -16,14 +16,14 @@ namespace Umbraco.Cms.Core.PropertyEditors } /// - public override LabelConfiguration FromConfigurationEditor(IDictionary editorValues, LabelConfiguration? configuration) + public override LabelConfiguration FromConfigurationEditor(IDictionary? editorValues, LabelConfiguration? configuration) { var newConfiguration = new LabelConfiguration(); // get the value type // not simply deserializing Json because we want to validate the valueType - if (editorValues.TryGetValue(Cms.Core.Constants.PropertyEditors.ConfigurationKeys.DataValueType, out var valueTypeObj) + if (editorValues is not null && editorValues.TryGetValue(Cms.Core.Constants.PropertyEditors.ConfigurationKeys.DataValueType, out var valueTypeObj) && valueTypeObj is string stringValue) { if (!string.IsNullOrWhiteSpace(stringValue) && ValueTypes.IsValue(stringValue)) // validate diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs index 9d2daeb92e..60777010d6 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs @@ -35,13 +35,13 @@ namespace Umbraco.Cms.Core.PropertyEditors } /// - public override MultipleTextStringConfiguration FromConfigurationEditor(IDictionary editorValues, MultipleTextStringConfiguration? configuration) + public override MultipleTextStringConfiguration FromConfigurationEditor(IDictionary? editorValues, MultipleTextStringConfiguration? configuration) { // TODO: this isn't pretty //the values from the editor will be min/max fields and we need to format to json in one field // is the editor sending strings or ints or?! - var min = (editorValues.ContainsKey("min") ? editorValues["min"].ToString() : "0").TryConvertTo(); - var max = (editorValues.ContainsKey("max") ? editorValues["max"].ToString() : "0").TryConvertTo(); + var min = (editorValues?.ContainsKey("min") ?? false ? editorValues["min"]?.ToString() : "0").TryConvertTo(); + var max = (editorValues?.ContainsKey("max") ?? false ? editorValues["max"]?.ToString() : "0").TryConvertTo(); return new MultipleTextStringConfiguration { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/TagConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/TagConfigurationEditor.cs index e32e765a00..7cd33e0066 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/TagConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/TagConfigurationEditor.cs @@ -33,14 +33,18 @@ namespace Umbraco.Cms.Core.PropertyEditors return dictionary; } - public override TagConfiguration? FromConfigurationEditor(IDictionary editorValues, TagConfiguration? configuration) + public override TagConfiguration? FromConfigurationEditor(IDictionary? editorValues, TagConfiguration? configuration) { // the front-end editor returns the string value of the storage type // pure Json could do with // [JsonConverter(typeof(StringEnumConverter))] // but here we're only deserializing to object and it's too late - editorValues["storageType"] = Enum.Parse(typeof(TagsStorageType), (string) editorValues["storageType"]); + if (editorValues is not null) + { + editorValues["storageType"] = Enum.Parse(typeof(TagsStorageType), (string) editorValues["storageType"]!); + } + return base.FromConfigurationEditor(editorValues, configuration); } } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs index 2d7fda8b2e..fcb6dd8ae2 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs @@ -67,11 +67,11 @@ namespace Umbraco.Cms.Core.PropertyEditors } /// - public override ValueListConfiguration FromConfigurationEditor(IDictionary editorValues, ValueListConfiguration? configuration) + public override ValueListConfiguration FromConfigurationEditor(IDictionary? editorValues, ValueListConfiguration? configuration) { var output = new ValueListConfiguration(); - if (!editorValues.TryGetValue("items", out var jjj) || !(jjj is JArray jItems)) + if (editorValues is null || !editorValues.TryGetValue("items", out var jjj) || !(jjj is JArray jItems)) return output; // oops // auto-assigning our ids, get next id from existing values diff --git a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs index 48088db073..0cf3b5879e 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs @@ -588,7 +588,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers // IMember on the PersistedContent with what is stored since it will be mapped to display. if (needsResync && contentItem.PersistedContent is not null) { - contentItem.PersistedContent = _memberService.GetById(contentItem.PersistedContent.Id); + contentItem.PersistedContent = _memberService.GetById(contentItem.PersistedContent.Id)!; } return true; diff --git a/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs b/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs index a6b9772d43..9234ed96b4 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs @@ -92,8 +92,11 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers //map the model to the persisted instance _umbracoMapper.Map(userGroupSave, userGroupSave.PersistedUserGroup); - //save the group - _userService.Save(userGroupSave.PersistedUserGroup, userGroupSave.Users?.ToArray()); + if (userGroupSave.PersistedUserGroup is not null) + { + //save the group + _userService.Save(userGroupSave.PersistedUserGroup, userGroupSave.Users?.ToArray()); + } //deal with permissions diff --git a/src/Umbraco.Web.BackOffice/ModelBinders/MediaItemBinder.cs b/src/Umbraco.Web.BackOffice/ModelBinders/MediaItemBinder.cs index c71c686827..fcedb0a0af 100644 --- a/src/Umbraco.Web.BackOffice/ModelBinders/MediaItemBinder.cs +++ b/src/Umbraco.Web.BackOffice/ModelBinders/MediaItemBinder.cs @@ -49,7 +49,7 @@ namespace Umbraco.Cms.Web.BackOffice.ModelBinders return; } - model.PersistedContent = ContentControllerBase.IsCreatingAction(model.Action) ? CreateNew(model) : GetExisting(model); + model.PersistedContent = ContentControllerBase.IsCreatingAction(model.Action) ? CreateNew(model) : GetExisting(model)!; //create the dto from the persisted model if (model.PersistedContent != null) diff --git a/src/Umbraco.Web.Common/Extensions/EndpointRouteBuilderExtensions.cs b/src/Umbraco.Web.Common/Extensions/EndpointRouteBuilderExtensions.cs index f60ca6fe00..a8afeccdbb 100644 --- a/src/Umbraco.Web.Common/Extensions/EndpointRouteBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/EndpointRouteBuilderExtensions.cs @@ -15,7 +15,7 @@ namespace Umbraco.Extensions this IEndpointRouteBuilder endpoints, Type controllerType, string rootSegment, - string areaName, + string? areaName, string? prefixPathSegment, string defaultAction = "Index", bool includeControllerNameInRoute = true, @@ -57,7 +57,7 @@ namespace Umbraco.Extensions // named consistently $"umbraco-{areaName}-{controllerName}".ToLowerInvariant(), - areaName, + areaName!, pattern.ToString().ToLowerInvariant(), defaults, constraints); @@ -98,7 +98,7 @@ namespace Umbraco.Extensions /// public static void MapUmbracoApiRoute( this IEndpointRouteBuilder endpoints, - Type? controllerType, + Type controllerType, string rootSegment, string? areaName, bool isBackOffice, diff --git a/src/Umbraco.Web.Common/Extensions/ViewDataExtensions.cs b/src/Umbraco.Web.Common/Extensions/ViewDataExtensions.cs index 39ee98f09e..2cf6c6f8b9 100644 --- a/src/Umbraco.Web.Common/Extensions/ViewDataExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/ViewDataExtensions.cs @@ -47,7 +47,7 @@ namespace Umbraco.Extensions if (!hasCookie) return false; // get the cookie value - if (!httpContext.Request.Cookies.TryGetValue(cookieName, out var cookieVal)) + if (httpContext is null || !httpContext.Request.Cookies.TryGetValue(cookieName, out var cookieVal)) { return false; } diff --git a/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs b/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs index 10ee133684..b1e5250992 100644 --- a/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs +++ b/src/Umbraco.Web.Common/ModelsBuilder/ModelsBuilderNotificationHandler.cs @@ -57,7 +57,7 @@ namespace Umbraco.Cms.Web.Common.ModelsBuilder throw new ArgumentException("Null umbracoUrls"); } - if (!(umbracoUrlsObject is Dictionary umbracoUrls)) + if (!(umbracoUrlsObject is Dictionary umbracoUrls)) { throw new ArgumentException("Invalid umbracoUrls"); } diff --git a/tests/Umbraco.Tests.Benchmarks/CombineGuidBenchmarks.cs b/tests/Umbraco.Tests.Benchmarks/CombineGuidBenchmarks.cs index 1a13545df8..6f7cea07ca 100644 --- a/tests/Umbraco.Tests.Benchmarks/CombineGuidBenchmarks.cs +++ b/tests/Umbraco.Tests.Benchmarks/CombineGuidBenchmarks.cs @@ -13,7 +13,7 @@ namespace Umbraco.Tests.Benchmarks private static readonly Guid _b = Guid.NewGuid(); [Benchmark] - public byte[] CombineUtils() => GuidUtils.Combine(_a, _b)?.ToByteArray(); + public byte[] CombineUtils() => GuidUtils.Combine(_a, _b).ToByteArray(); [Benchmark] public byte[] CombineLoop() => Combine(_a, _b); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/GuidUtilsTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/GuidUtilsTests.cs index 9b4bfd966b..da9865e72e 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/GuidUtilsTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/GuidUtilsTests.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core var a = Guid.NewGuid(); var b = Guid.NewGuid(); - Assert.AreEqual(GuidUtils.Combine(a, b)?.ToByteArray(), Combine(a, b)); + Assert.AreEqual(GuidUtils.Combine(a, b).ToByteArray(), Combine(a, b)); } [Test]