From aaa619b3a391bd4f2a36fe1612c552445066d160 Mon Sep 17 00:00:00 2001 From: Philip Niedertscheider Date: Wed, 13 Aug 2025 10:35:58 +0200 Subject: [PATCH] refactor: Add null-handling to multiple types --- Sources/Sentry/SentryBinaryImageCache.m | 2 +- Sources/Sentry/SentryBreadcrumb.m | 14 +++++++++----- Sources/Sentry/SentryBreadcrumbTracker.m | 6 ++++-- Sources/Sentry/SentryClient.m | 3 ++- Sources/Sentry/SentryCoreDataTracker.m | 2 +- Sources/Sentry/SentryDebugImageProvider.m | 12 ++++++++++-- Sources/Sentry/SentryDevice.m | 4 +++- Sources/Sentry/SentryProfiler.mm | 7 ++++--- Sources/Sentry/SentryUserFeedbackIntegration.m | 4 +++- 9 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Sources/Sentry/SentryBinaryImageCache.m b/Sources/Sentry/SentryBinaryImageCache.m index 83edebe355a..73d7b2a37db 100644 --- a/Sources/Sentry/SentryBinaryImageCache.m +++ b/Sources/Sentry/SentryBinaryImageCache.m @@ -67,7 +67,7 @@ - (void)binaryImageAdded:(const SentryCrashBinaryImage *)image } SentryBinaryImageInfo *newImage = [[SentryBinaryImageInfo alloc] init]; - newImage.name = imageName; + newImage.name = SENTRY_UNWRAP_NULLABLE(NSString, imageName); newImage.UUID = [SentryBinaryImageCache convertUUID:image->uuid]; newImage.address = image->address; newImage.vmAddress = image->vmAddress; diff --git a/Sources/Sentry/SentryBreadcrumb.m b/Sources/Sentry/SentryBreadcrumb.m index 284e5082084..bdcf42b208a 100644 --- a/Sources/Sentry/SentryBreadcrumb.m +++ b/Sources/Sentry/SentryBreadcrumb.m @@ -95,15 +95,19 @@ - (BOOL)isEqualToBreadcrumb:(SentryBreadcrumb *)breadcrumb && ![self.category isEqualToString:breadcrumb.category]) return NO; if (self.timestamp != breadcrumb.timestamp - && ![self.timestamp isEqualToDate:breadcrumb.timestamp]) + && ![self.timestamp isEqualToDate:SENTRY_UNWRAP_NULLABLE(NSDate, breadcrumb.timestamp)]) return NO; - if (self.type != breadcrumb.type && ![self.type isEqualToString:breadcrumb.type]) + if (self.type != breadcrumb.type + && ![self.type isEqualToString:SENTRY_UNWRAP_NULLABLE(NSString, breadcrumb.type)]) return NO; - if (self.origin != breadcrumb.origin && ![self.origin isEqualToString:breadcrumb.origin]) + if (self.origin != breadcrumb.origin + && ![self.origin isEqualToString:SENTRY_UNWRAP_NULLABLE(NSString, breadcrumb.origin)]) return NO; - if (self.message != breadcrumb.message && ![self.message isEqualToString:breadcrumb.message]) + if (self.message != breadcrumb.message + && ![self.message isEqualToString:SENTRY_UNWRAP_NULLABLE(NSString, breadcrumb.message)]) return NO; - if (self.data != breadcrumb.data && ![self.data isEqualToDictionary:breadcrumb.data]) + if (self.data != breadcrumb.data + && ![self.data isEqualToDictionary:SENTRY_UNWRAP_NULLABLE(NSDictionary, breadcrumb.data)]) return NO; return YES; } diff --git a/Sources/Sentry/SentryBreadcrumbTracker.m b/Sources/Sentry/SentryBreadcrumbTracker.m index 750c9455d5c..872aefaadc9 100644 --- a/Sources/Sentry/SentryBreadcrumbTracker.m +++ b/Sources/Sentry/SentryBreadcrumbTracker.m @@ -5,6 +5,7 @@ #import "SentryDefines.h" #import "SentryDependencyContainer.h" #import "SentryHub.h" +#import "SentryInternalDefines.h" #import "SentryLogC.h" #import "SentryReachability.h" #import "SentryScope.h" @@ -220,9 +221,10 @@ - (void)swizzleSendAction NSDictionary *data = nil; for (UITouch *touch in event.allTouches) { - if (touch.phase == UITouchPhaseCancelled || touch.phase == UITouchPhaseEnded) { + if (touch.view != nil + && (touch.phase == UITouchPhaseCancelled || touch.phase == UITouchPhaseEnded)) { data = [SentryBreadcrumbTracker - extractDataFromView:touch.view + extractDataFromView:SENTRY_UNWRAP_NULLABLE_VALUE(id, touch.view) withAccessibilityIdentifier:self->_reportAccessibilityIdentifier]; } } diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index 37ac25c4956..feb5a795059 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -1053,7 +1053,8 @@ - (void)applyCurrentViewNamesToEventContext:(SentryEvent *)event withScope:(Sent } } else { if (scope.currentScreen != nil) { - app[@"view_names"] = @[ scope.currentScreen ]; + app[@"view_names"] = + @[ SENTRY_UNWRAP_NULLABLE(NSString, scope.currentScreen) ]; } else { app[@"view_names"] = [SentryDependencyContainer.sharedInstance .application relevantViewControllersNames]; diff --git a/Sources/Sentry/SentryCoreDataTracker.m b/Sources/Sentry/SentryCoreDataTracker.m index 7eee6b31ed1..8a9154b23ea 100644 --- a/Sources/Sentry/SentryCoreDataTracker.m +++ b/Sources/Sentry/SentryCoreDataTracker.m @@ -125,7 +125,7 @@ - (void)addExtraInfoToSpan:(SentrySpan *)span withContext:(NSManagedObjectContex __kindof NSPersistentStore *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) { [systems addObject:obj.type]; if (obj.URL != nil) { - [names addObject:obj.URL.path]; + [names addObject:SENTRY_UNWRAP_NULLABLE(NSString, obj.URL.path)]; } else { [names addObject:@"(null)"]; } diff --git a/Sources/Sentry/SentryDebugImageProvider.m b/Sources/Sentry/SentryDebugImageProvider.m index 34c1c41e710..ea53b532d08 100644 --- a/Sources/Sentry/SentryDebugImageProvider.m +++ b/Sources/Sentry/SentryDebugImageProvider.m @@ -120,7 +120,11 @@ - (void)extractDebugImageAddressFromFrames:(NSArray *)frames NSMutableSet *imageAddresses = [[NSMutableSet alloc] init]; for (SentryThread *thread in threads) { - [self extractDebugImageAddressFromFrames:thread.stacktrace.frames intoSet:imageAddresses]; + NSArray *_Nullable frames = thread.stacktrace.frames; + if (frames != nil) { + [self extractDebugImageAddressFromFrames:SENTRY_UNWRAP_NULLABLE(NSArray, frames) + intoSet:imageAddresses]; + } } return [self getDebugImagesForAddresses:imageAddresses isCrash:isCrash]; @@ -179,7 +183,11 @@ - (void)extractDebugImageAddressFromFrames:(NSArray *)frames NSMutableSet *imageAddresses = [[NSMutableSet alloc] init]; for (SentryThread *thread in threads) { - [self extractDebugImageAddressFromFrames:thread.stacktrace.frames intoSet:imageAddresses]; + NSArray *_Nullable frames = thread.stacktrace.frames; + if (frames != nil) { + [self extractDebugImageAddressFromFrames:SENTRY_UNWRAP_NULLABLE(NSArray, frames) + intoSet:imageAddresses]; + } } return [self getDebugImagesForImageAddressesFromCache:imageAddresses]; diff --git a/Sources/Sentry/SentryDevice.m b/Sources/Sentry/SentryDevice.m index edca69d4f2a..1c11ebd59d2 100644 --- a/Sources/Sentry/SentryDevice.m +++ b/Sources/Sentry/SentryDevice.m @@ -15,6 +15,8 @@ // #import "SentryDevice.h" +#import "SentryInternalDefines.h" + #import #if TARGET_OS_WATCH # import @@ -236,7 +238,7 @@ size_t size = sizeof(str); int cmd[2] = { CTL_KERN, KERN_OSVERSION }; if (SENTRY_LOG_ERRNO(sysctl(cmd, sizeof(cmd) / sizeof(*cmd), str, &size, NULL, 0)) == 0) { - return [NSString stringWithUTF8String:str]; + return SENTRY_UNWRAP_NULLABLE(NSString, [NSString stringWithUTF8String:str]); } return @""; } diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index e09160503ea..e8aa20bb571 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -56,11 +56,12 @@ return NO; } - SentryProfileOptions *options = sentry_profileConfiguration.profileOptions; - - if (nil == options) { + SentryProfileOptions *_Nullable nullableOptions = sentry_profileConfiguration.profileOptions; + if (nil == nullableOptions) { return !sentry_profileConfiguration.isContinuousV1; } + SentryProfileOptions *_Nonnull options + = SENTRY_UNWRAP_NULLABLE(SentryProfileOptions, nullableOptions); return sentry_profileAppStarts(options) && sentry_isTraceLifecycle(options); } diff --git a/Sources/Sentry/SentryUserFeedbackIntegration.m b/Sources/Sentry/SentryUserFeedbackIntegration.m index b14188afdd9..b44ad68a5e8 100644 --- a/Sources/Sentry/SentryUserFeedbackIntegration.m +++ b/Sources/Sentry/SentryUserFeedbackIntegration.m @@ -1,5 +1,6 @@ #import "SentryUserFeedbackIntegration.h" #import "SentryDependencyContainer.h" +#import "SentryInternalDefines.h" #import "SentryOptions+Private.h" #import "SentrySDK+Private.h" #import "SentrySwift.h" @@ -20,7 +21,8 @@ - (BOOL)installWithOptions:(SentryOptions *)options } _driver = [[SentryUserFeedbackIntegrationDriver alloc] - initWithConfiguration:options.userFeedbackConfiguration + initWithConfiguration:SENTRY_UNWRAP_NULLABLE(SentryUserFeedbackConfiguration, + options.userFeedbackConfiguration) delegate:self screenshotProvider:SentryDependencyContainer.sharedInstance.screenshot]; return YES;