Skip to content

Commit 480185d

Browse files
authored
refactor: Add null unwrapping to silence handled nullability warnings (#5752)
1 parent 39280ec commit 480185d

25 files changed

+104
-52
lines changed

Sources/Sentry/Processors/SentryWatchdogTerminationBreadcrumbProcessor.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "SentryWatchdogTerminationBreadcrumbProcessor.h"
22
#import "SentryFileManager.h"
3+
#import "SentryInternalDefines.h"
34
#import "SentryLogC.h"
45
#import "SentrySerialization.h"
56

@@ -44,7 +45,7 @@ - (void)addSerializedBreadcrumb:(NSDictionary *)crumb
4445
SENTRY_LOG_ERROR(@"Error serializing breadcrumb to JSON");
4546
return;
4647
}
47-
[self storeBreadcrumb:jsonData];
48+
[self storeBreadcrumb:SENTRY_UNWRAP_NULLABLE(NSData, jsonData)];
4849
}
4950

5051
- (void)clear

Sources/Sentry/SentryBinaryImageCache.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#import "SentryDefaultObjCRuntimeWrapper.h"
55
#import "SentryDependencyContainer.h"
66
#import "SentryInAppLogic.h"
7+
#import "SentryInternalDefines.h"
78
#import "SentryLogC.h"
89
#import "SentrySDK+Private.h"
910
#import "SentrySwift.h"
@@ -176,7 +177,7 @@ - (NSInteger)indexOfImage:(uint64_t)address
176177
- (NSArray<SentryBinaryImageInfo *> *)getAllBinaryImages
177178
{
178179
@synchronized(self) {
179-
return _cache.copy;
180+
return SENTRY_UNWRAP_NULLABLE(NSArray<SentryBinaryImageInfo *>, _cache.copy);
180181
}
181182
}
182183

Sources/Sentry/SentryBreadcrumb.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ - (BOOL)isEqual:(id _Nullable)other
8080
if (!other || ![[other class] isEqual:[self class]])
8181
return NO;
8282

83-
return [self isEqualToBreadcrumb:other];
83+
return [self isEqualToBreadcrumb:SENTRY_UNWRAP_NULLABLE(SentryBreadcrumb, other)];
8484
}
8585

8686
- (BOOL)isEqualToBreadcrumb:(SentryBreadcrumb *)breadcrumb

Sources/Sentry/SentryBreadcrumbTracker.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,14 @@ + (NSDictionary *)fetchInfoAboutViewController:(UIViewController *)controller
316316

317317
if (controller.presentingViewController != nil) {
318318
info[@"presentingViewController"] =
319-
[SwiftDescriptor getViewControllerClassName:controller.presentingViewController];
319+
[SwiftDescriptor getViewControllerClassName:SENTRY_UNWRAP_NULLABLE(UIViewController,
320+
controller.presentingViewController)];
320321
}
321322

322323
if (controller.parentViewController != nil) {
323324
info[@"parentViewController"] =
324-
[SwiftDescriptor getViewControllerClassName:controller.parentViewController];
325+
[SwiftDescriptor getViewControllerClassName:SENTRY_UNWRAP_NULLABLE(UIViewController,
326+
controller.parentViewController)];
325327
}
326328

327329
if (controller.view.window != nil) {

Sources/Sentry/SentryCoreDataTracker.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ - (NSString *)descriptionFromRequest:(NSFetchRequest *)request
204204

205205
if (request.predicate) {
206206
[result appendFormat:@" WHERE %@",
207-
[predicateDescriptor predicateDescription:request.predicate]];
207+
[predicateDescriptor
208+
predicateDescription:SENTRY_UNWRAP_NULLABLE(NSPredicate, request.predicate)]];
208209
}
209210

210211
if (request.sortDescriptors.count > 0) {

Sources/Sentry/SentryCrashIntegrationSessionHandler.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#import "SentryDependencyContainer.h"
55
#import "SentryFileManager.h"
66
#import "SentryHub.h"
7+
#import "SentryInternalDefines.h"
78
#import "SentryLogC.h"
89
#import "SentrySDK+Private.h"
910
#import "SentrySession.h"
@@ -81,7 +82,8 @@ - (void)endCurrentSessionIfRequired
8182
return;
8283
}
8384

84-
[session endSessionAbnormalWithTimestamp:appHangEvent.timestamp];
85+
[session
86+
endSessionAbnormalWithTimestamp:SENTRY_UNWRAP_NULLABLE(NSDate, appHangEvent).timestamp];
8587
[fileManager storeAbnormalSession:session];
8688
[fileManager deleteCurrentSession];
8789
}

Sources/Sentry/SentryDateUtil.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "SentryDateUtil.h"
2+
#import "SentryInternalDefines.h"
23
#import "SentrySwift.h"
34

45
NS_ASSUME_NONNULL_BEGIN
@@ -24,7 +25,8 @@ - (BOOL)isInFuture:(NSDate *_Nullable)date
2425
if (date == nil)
2526
return NO;
2627

27-
NSComparisonResult result = [[self.currentDateProvider date] compare:date];
28+
NSComparisonResult result =
29+
[[self.currentDateProvider date] compare:SENTRY_UNWRAP_NULLABLE(NSDate, date)];
2830
return result == NSOrderedAscending;
2931
}
3032

@@ -37,7 +39,8 @@ + (NSDate *_Nullable)getMaximumDate:(NSDate *_Nullable)first andOther:(NSDate *_
3739
if (second == nil)
3840
return first;
3941

40-
NSComparisonResult result = [first compare:second];
42+
NSComparisonResult result =
43+
[SENTRY_UNWRAP_NULLABLE(NSDate, first) compare:SENTRY_UNWRAP_NULLABLE(NSDate, second)];
4144
if (result == NSOrderedDescending) {
4245
return first;
4346
} else {

Sources/Sentry/SentryDebugImageProvider.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ - (void)extractDebugImageAddressFromFrames:(NSArray<SentryFrame *> *)frames
6767
{
6868
for (SentryFrame *frame in frames) {
6969
if (frame.imageAddress) {
70-
[set addObject:frame.imageAddress];
70+
[set addObject:SENTRY_UNWRAP_NULLABLE(NSString, frame.imageAddress)];
7171
}
7272
}
7373
}
@@ -85,7 +85,8 @@ - (void)extractDebugImageAddressFromFrames:(NSArray<SentryFrame *> *)frames
8585
# pragma clang diagnostic pop
8686

8787
for (SentryDebugMeta *sourceImage in binaryImages) {
88-
if ([addresses containsObject:sourceImage.imageAddress]) {
88+
if (sourceImage.imageAddress &&
89+
[addresses containsObject:SENTRY_UNWRAP_NULLABLE(NSString, sourceImage.imageAddress)]) {
8990
[result addObject:sourceImage];
9091
}
9192
}

Sources/Sentry/SentryDefaultRateLimits.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#import "SentryConcurrentRateLimitsDictionary.h"
33
#import "SentryDataCategoryMapper.h"
44
#import "SentryDateUtil.h"
5+
#import "SentryInternalDefines.h"
56
#import "SentryLogC.h"
67
#import "SentryRateLimitParser.h"
78
#import "SentryRetryAfterHeaderParser.h"
@@ -62,7 +63,8 @@ - (void)update:(NSHTTPURLResponse *)response
6263
SentryDataCategory category
6364
= sentryDataCategoryForNSUInteger(categoryAsNumber.unsignedIntegerValue);
6465

65-
[self updateRateLimit:category withDate:limits[categoryAsNumber]];
66+
[self updateRateLimit:category
67+
withDate:SENTRY_UNWRAP_NULLABLE(NSDate, limits[categoryAsNumber])];
6668
}
6769
} else if (response.statusCode == 429) {
6870
NSDate *retryAfterHeaderDate =

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "SentryFileIOTracker.h"
1010
#import "SentryFileManager.h"
1111
#import "SentryInternalCDefines.h"
12+
#import "SentryInternalDefines.h"
1213
#import "SentryLogC.h"
1314
#import "SentryNSProcessInfoWrapper.h"
1415
#import "SentryNSTimerFactory.h"
@@ -28,7 +29,6 @@
2829
#import <SentryDependencyContainer.h>
2930
#import <SentryGlobalEventProcessor.h>
3031
#import <SentryHttpDateParser.h>
31-
#import <SentryInternalDefines.h>
3232
#import <SentryPerformanceTracker.h>
3333
#import <SentryRateLimitParser.h>
3434
#import <SentryRetryAfterHeaderParser.h>

0 commit comments

Comments
 (0)