Skip to content

Commit dcf28a2

Browse files
committed
refactor: Add null unwrapping to silence already handled nullability warnings
1 parent 64c2b2b commit dcf28a2

25 files changed

+91
-52
lines changed

Sources/Sentry/PrivateSentrySDKOnly.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ + (SentryScreenFrames *)currentScreenFrames
292292
}
293293

294294
#if SENTRY_UIKIT_AVAILABLE
295-
+ (void)setCurrentScreen:(NSString *)screenName
295+
+ (void)setCurrentScreen:(NSString *_Nullable)screenName
296296
{
297297
[SentrySDKInternal.currentHub
298298
configureScope:^(SentryScope *scope) { scope.currentScreen = screenName; }];

Sources/Sentry/Processors/SentryWatchdogTerminationBreadcrumbProcessor.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ - (void)addSerializedBreadcrumb:(NSDictionary *)crumb
4444
SENTRY_LOG_ERROR(@"Error serializing breadcrumb to JSON");
4545
return;
4646
}
47-
[self storeBreadcrumb:jsonData];
47+
[self storeBreadcrumb:SENTRY_UNWRAP_NULLABLE(NSData, jsonData)];
4848
}
4949

5050
- (void)clear

Sources/Sentry/Public/SentryDefines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,6 @@ typedef void (^SentryUserFeedbackConfigurationBlock)(
220220
* pattern in the codebase.
221221
*/
222222
#define SENTRY_UNWRAP_NULLABLE(type, nullable_var) (type *_Nonnull)(nullable_var)
223+
#define SENTRY_UNWRAP_NULLABLE_VALUE(type, nullable_var) (type _Nonnull)(nullable_var)
224+
#define SENTRY_UNWRAP_NULLABLE_DICT(key, value, nullable_var) \
225+
(NSDictionary<key, value> *_Nonnull)(nullable_var)

Sources/Sentry/SentryBinaryImageCache.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ - (NSInteger)indexOfImage:(uint64_t)address
176176
- (NSArray<SentryBinaryImageInfo *> *)getAllBinaryImages
177177
{
178178
@synchronized(self) {
179-
return _cache.copy;
179+
return SENTRY_UNWRAP_NULLABLE(NSArray<SentryBinaryImageInfo *>, _cache.copy);
180180
}
181181
}
182182

Sources/Sentry/SentryBreadcrumb.m

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

78-
return [self isEqualToBreadcrumb:other];
78+
return [self isEqualToBreadcrumb:SENTRY_UNWRAP_NULLABLE(SentryBreadcrumb, other)];
7979
}
8080

8181
- (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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ - (void)endCurrentSessionIfRequired
8181
return;
8282
}
8383

84-
[session endSessionAbnormalWithTimestamp:appHangEvent.timestamp];
84+
[session
85+
endSessionAbnormalWithTimestamp:SENTRY_UNWRAP_NULLABLE(NSDate, appHangEvent).timestamp];
8586
[fileManager storeAbnormalSession:session];
8687
[fileManager deleteCurrentSession];
8788
}

Sources/Sentry/SentryDateUtil.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ - (BOOL)isInFuture:(NSDate *_Nullable)date
2424
if (date == nil)
2525
return NO;
2626

27-
NSComparisonResult result = [[self.currentDateProvider date] compare:date];
27+
NSComparisonResult result =
28+
[[self.currentDateProvider date] compare:SENTRY_UNWRAP_NULLABLE(NSDate, date)];
2829
return result == NSOrderedAscending;
2930
}
3031

@@ -37,7 +38,8 @@ + (NSDate *_Nullable)getMaximumDate:(NSDate *_Nullable)first andOther:(NSDate *_
3738
if (second == nil)
3839
return first;
3940

40-
NSComparisonResult result = [first compare:second];
41+
NSComparisonResult result =
42+
[SENTRY_UNWRAP_NULLABLE(NSDate, first) compare:SENTRY_UNWRAP_NULLABLE(NSDate, second)];
4143
if (result == NSOrderedDescending) {
4244
return first;
4345
} 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
}

0 commit comments

Comments
 (0)