Skip to content

Commit 781f560

Browse files
authored
fix: Resolve remaining nullability warnings and enabling them as errors (#6563)
1 parent 36c0d1a commit 781f560

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+380
-190
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Remove unused `SentryFrame.instruction` property (#6504)
2424
- Remove `uuid` and `name` of `SentryDebugMeta` (#6512) Use `debugID` instead of `uuid` and `codeFile` instead of `name`.
2525
- Enable enablePreWarmedAppStartTracing by default (#6508). With this option enabled, the SDK collects [prewarmed app starts](https://docs.sentry.io/platforms/apple/tracing/instrumentation/automatic-instrumentation/#prewarmed-app-start-tracing).
26+
- Change `value` and `type` of `SentryException` to be nullable (#6563)
2627

2728
### Features
2829

Sentry.xcodeproj/project.pbxproj

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6636,8 +6636,6 @@
66366636
OTHER_CFLAGS = (
66376637
"-Wnullable-to-nonnull-conversion",
66386638
"-Wnullability-completeness",
6639-
"-Wno-error=nullable-to-nonnull-conversion",
6640-
"-Wno-error=nullability-completeness",
66416639
);
66426640
};
66436641
name = Debug;
@@ -6650,8 +6648,6 @@
66506648
OTHER_CFLAGS = (
66516649
"-Wnullable-to-nonnull-conversion",
66526650
"-Wnullability-completeness",
6653-
"-Wno-error=nullable-to-nonnull-conversion",
6654-
"-Wno-error=nullability-completeness",
66556651
);
66566652
};
66576653
name = Release;
@@ -6747,8 +6743,6 @@
67476743
OTHER_CFLAGS = (
67486744
"-Wnullable-to-nonnull-conversion",
67496745
"-Wnullability-completeness",
6750-
"-Wno-error=nullable-to-nonnull-conversion",
6751-
"-Wno-error=nullability-completeness",
67526746
);
67536747
};
67546748
name = TestCI;
@@ -6810,8 +6804,6 @@
68106804
OTHER_CFLAGS = (
68116805
"-Wnullable-to-nonnull-conversion",
68126806
"-Wnullability-completeness",
6813-
"-Wno-error=nullable-to-nonnull-conversion",
6814-
"-Wno-error=nullability-completeness",
68156807
);
68166808
};
68176809
name = DebugWithoutUIKit;
@@ -7219,8 +7211,6 @@
72197211
OTHER_CFLAGS = (
72207212
"-Wnullable-to-nonnull-conversion",
72217213
"-Wnullability-completeness",
7222-
"-Wno-error=nullable-to-nonnull-conversion",
7223-
"-Wno-error=nullability-completeness",
72247214
);
72257215
};
72267216
name = ReleaseWithoutUIKit;
@@ -7516,8 +7506,6 @@
75167506
OTHER_CFLAGS = (
75177507
"-Wnullable-to-nonnull-conversion",
75187508
"-Wnullability-completeness",
7519-
"-Wno-error=nullable-to-nonnull-conversion",
7520-
"-Wno-error=nullability-completeness",
75217509
);
75227510
};
75237511
name = Test;
@@ -8282,8 +8270,6 @@
82828270
OTHER_CFLAGS = (
82838271
"-Wnullable-to-nonnull-conversion",
82848272
"-Wnullability-completeness",
8285-
"-Wno-error=nullable-to-nonnull-conversion",
8286-
"-Wno-error=nullability-completeness",
82878273
);
82888274
};
82898275
name = DebugV9;
@@ -8564,8 +8550,6 @@
85648550
OTHER_CFLAGS = (
85658551
"-Wnullable-to-nonnull-conversion",
85668552
"-Wnullability-completeness",
8567-
"-Wno-error=nullable-to-nonnull-conversion",
8568-
"-Wno-error=nullability-completeness",
85698553
);
85708554
};
85718555
name = ReleaseV9;

Sources/Sentry/PrivateSentrySDKOnly.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ + (SentryScreenFrames *)currentScreenFrames
261261
#if SENTRY_TARGET_REPLAY_SUPPORTED
262262
// As the options are not passed in by the hybrid SDK, we need to use the options from the
263263
// current hub.
264-
SentryScreenshotSource *_Nonnull screenshotSource
264+
SentryScreenshotSource *_Nullable screenshotSource
265265
= SentryDependencyContainer.sharedInstance.screenshotSource;
266-
return [screenshotSource appScreenshotsData];
266+
if (!screenshotSource) {
267+
return nil;
268+
}
269+
return [SENTRY_UNWRAP_NULLABLE(SentryScreenshotSource, screenshotSource) appScreenshotsData];
267270
#else
268271
SENTRY_LOG_DEBUG(
269272
@"PrivateSentrySDKOnly.captureScreenshots only works with UIKit enabled. Ensure you're "
@@ -283,7 +286,13 @@ + (void)setCurrentScreen:(NSString *_Nullable)screenName
283286
+ (NSData *)captureViewHierarchy
284287
{
285288
#if SENTRY_HAS_UIKIT
286-
return [SentryDependencyContainer.sharedInstance.viewHierarchyProvider appViewHierarchy];
289+
SentryViewHierarchyProvider *_Nullable viewHierarchyProvider
290+
= SentryDependencyContainer.sharedInstance.viewHierarchyProvider;
291+
if (!viewHierarchyProvider) {
292+
return nil;
293+
}
294+
return [SENTRY_UNWRAP_NULLABLE(SentryViewHierarchyProvider, viewHierarchyProvider)
295+
appViewHierarchy];
287296
#else
288297
SENTRY_LOG_DEBUG(
289298
@"PrivateSentrySDKOnly.captureViewHierarchy only works with UIKit enabled. Ensure you're "

Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
void
241241
sentry_stopProfilerDueToFinishedTransaction(
242242
SentryHub *hub, SentryDispatchQueueWrapper *dispatchQueue, SentryTransaction *transaction,
243-
BOOL isProfiling, NSDate *traceStartTimestamp, uint64_t startSystemTime
243+
BOOL isProfiling, NSDate *_Nullable traceStartTimestamp, uint64_t startSystemTime
244244
# if SENTRY_HAS_UIKIT
245245
,
246246
SentryAppStartMeasurement *appStartMeasurement
@@ -334,7 +334,7 @@
334334
}
335335

336336
SentryId *_Nullable sentry_startProfilerForTrace(SentryTracerConfiguration *configuration,
337-
SentryHub *hub, SentryTransactionContext *transactionContext)
337+
SentryHub *_Nullable hub, SentryTransactionContext *transactionContext)
338338
{
339339
if (sentry_profileConfiguration.profileOptions != nil) {
340340
// launch profile; there's no hub to get options from, so they're read from the launch

Sources/Sentry/Profiling/SentryProfilerSerialization.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,12 @@
385385
NSMutableDictionary *transactionDict = [[NSMutableDictionary alloc] initWithDictionary:@ {
386386
@"id" : transaction.eventId.sentryIdString,
387387
@"trace_id" : transaction.trace.traceId.sentryIdString,
388-
@"active_thread_id" : [transaction.trace.transactionContext sentry_threadInfo].threadId
389388
}];
389+
NSNumber *_Nullable activeThreadId =
390+
[transaction.trace.transactionContext sentry_threadInfo].threadId;
391+
if (activeThreadId != nil || [activeThreadId isEqual:@0]) {
392+
transactionDict[@"active_thread_id"] = activeThreadId;
393+
}
390394
if (transaction.transaction) {
391395
transactionDict[@"name"] = transaction.transaction;
392396
}

Sources/Sentry/Public/SentryException.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ SENTRY_NO_INIT
2121
/**
2222
* The name of the exception
2323
*/
24-
@property (nonatomic, copy) NSString *value;
24+
@property (nonatomic, copy) NSString *_Nullable value;
2525

2626
/**
2727
* Type of the exception
2828
*/
29-
@property (nonatomic, copy) NSString *type;
29+
@property (nonatomic, copy) NSString *_Nullable type;
3030

3131
/**
3232
* Additional information about the exception
@@ -49,12 +49,13 @@ SENTRY_NO_INIT
4949
@property (nonatomic, strong) SentryStacktrace *_Nullable stacktrace;
5050

5151
/**
52-
* Initialize an SentryException with value and type
53-
* @param value String
54-
* @param type String
52+
* Initialize an SentryException with value and type.
53+
* @param value Nullable string describing the exception
54+
* @param type Nullable string with the type of the exception
5555
* @return SentryException
56+
* @note At least one of value or type must be non-nil. This is asserted in debug builds.
5657
*/
57-
- (instancetype)initWithValue:(NSString *)value type:(NSString *)type;
58+
- (instancetype)initWithValue:(NSString *_Nullable)value type:(NSString *_Nullable)type;
5859

5960
@end
6061

Sources/Sentry/SentryANRTrackingIntegration.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ - (BOOL)installWithOptions:(SentryOptions *)options
5151
[SentryDependencyContainer.sharedInstance getANRTracker:options.appHangTimeoutInterval];
5252

5353
#endif // SENTRY_HAS_UIKIT
54-
self.fileManager = SentryDependencyContainer.sharedInstance.fileManager;
54+
SentryFileManager *fileManager = SentryDependencyContainer.sharedInstance.fileManager;
55+
if (!fileManager) {
56+
SENTRY_LOG_FATAL(@"File manager is not available");
57+
return NO;
58+
}
59+
self.fileManager = fileManager;
5560
self.dispatchQueueWrapper = SentryDependencyContainer.sharedInstance.dispatchQueueWrapper;
5661
self.crashWrapper = SentryDependencyContainer.sharedInstance.crashWrapper;
5762
self.debugImageProvider = SentryDependencyContainer.sharedInstance.debugImageProvider;

Sources/Sentry/SentryAppStartTracker.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ - (void)buildAppStartMeasurement:(NSDate *)appStartEnd
188188
appStartDuration = 0;
189189
}
190190

191+
NSDate *sdkStart = SentrySDKInternal.startTimestamp;
192+
if (sdkStart == nil) {
193+
SENTRY_LOG_DEBUG(@"Skipping app start measurement: missing SDK start timestamp.");
194+
return;
195+
}
196+
191197
SentryAppStartMeasurement *appStartMeasurement =
192198
[[SentryAppStartMeasurement alloc] initWithType:appStartType
193199
isPreWarmed:isPreWarmed
@@ -196,7 +202,7 @@ - (void)buildAppStartMeasurement:(NSDate *)appStartEnd
196202
duration:appStartDuration
197203
runtimeInitTimestamp:runtimeInit
198204
moduleInitializationTimestamp:sysctl.moduleInitializationTimestamp
199-
sdkStartTimestamp:SentrySDKInternal.startTimestamp
205+
sdkStartTimestamp:sdkStart
200206
didFinishLaunchingTimestamp:self.didFinishLaunchingTimestamp];
201207

202208
SentrySDKInternal.appStartMeasurement = appStartMeasurement;

Sources/Sentry/SentryAutoBreadcrumbTrackingIntegration.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ - (BOOL)installWithOptions:(SentryOptions *)options
2626
return NO;
2727
}
2828

29+
SentryFileManager *_Nullable fileManager = SentryDependencyContainer.sharedInstance.fileManager;
30+
if (!fileManager) {
31+
SENTRY_LOG_FATAL(@"File manager is not available");
32+
return NO;
33+
}
34+
2935
#if TARGET_OS_IOS && SENTRY_HAS_UIKIT
3036
[self installWithOptions:options
3137
breadcrumbTracker:[[SentryBreadcrumbTracker alloc] initReportAccessibilityIdentifier:
3238
options.reportAccessibilityIdentifier]
33-
systemEventBreadcrumbs:
34-
[[SentrySystemEventBreadcrumbs alloc]
35-
initWithFileManager:[SentryDependencyContainer sharedInstance].fileManager
36-
andNotificationCenterWrapper:[SentryDependencyContainer sharedInstance]
37-
.notificationCenterWrapper]];
39+
systemEventBreadcrumbs:[[SentrySystemEventBreadcrumbs alloc]
40+
initWithFileManager:SENTRY_UNWRAP_NULLABLE(
41+
SentryFileManager, fileManager)
42+
andNotificationCenterWrapper:SentryDependencyContainer
43+
.sharedInstance
44+
.notificationCenterWrapper]];
3845
#else
3946
[self installWithOptions:options
4047
breadcrumbTracker:[[SentryBreadcrumbTracker alloc]

Sources/Sentry/SentryClient.m

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,10 @@ - (void)captureReplayEvent:(SentryReplayEvent *)replayEvent
555555

556556
// Hybrid SDKs may override the sdk info for a replay Event,
557557
// the same SDK should be used for the envelope header.
558-
SentrySdkInfo *sdkInfo = replayEvent.sdk ? [[SentrySdkInfo alloc] initWithDict:replayEvent.sdk]
559-
: [SentrySdkInfo global];
558+
SentrySdkInfo *sdkInfo = replayEvent.sdk
559+
? [[SentrySdkInfo alloc]
560+
initWithDict:SENTRY_UNWRAP_NULLABLE_DICT(NSString *, id, replayEvent.sdk)]
561+
: [SentrySdkInfo global];
560562
SentryEnvelopeHeader *envelopeHeader =
561563
[[SentryEnvelopeHeader alloc] initWithId:replayEvent.eventId
562564
sdkInfo:sdkInfo
@@ -664,7 +666,7 @@ - (void)close
664666
SENTRY_LOG_DEBUG(@"Closed the Client.");
665667
}
666668

667-
- (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
669+
- (SentryEvent *_Nullable)prepareEvent:(SentryEvent *_Nullable)event
668670
withScope:(SentryScope *)scope
669671
alwaysAttachStacktrace:(BOOL)alwaysAttachStacktrace
670672
isFatalEvent:(BOOL)isFatalEvent
@@ -713,7 +715,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
713715
event.dist = dist;
714716
}
715717

716-
[self setSdk:event];
718+
[self setSdk:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)];
717719

718720
// We don't want to attach debug meta and stacktraces for transactions, replays or user
719721
// feedback.
@@ -759,25 +761,29 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
759761
// Crash events are from a previous run. Applying the current scope would potentially apply
760762
// current data.
761763
if (!isFatalEvent) {
762-
event = [scope applyToEvent:event maxBreadcrumb:self.options.maxBreadcrumbs];
764+
// Unwrapping the event because we assume that the event will be returned
765+
event = SENTRY_UNWRAP_NULLABLE(
766+
SentryEvent, [scope applyToEvent:event maxBreadcrumb:self.options.maxBreadcrumbs]);
763767
}
764768

765769
if (!eventIsNotReplay) {
766770
event.breadcrumbs = nil;
767771
}
768772

769-
if ([self isWatchdogTermination:event isFatalEvent:isFatalEvent]) {
773+
if ([self isWatchdogTermination:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)
774+
isFatalEvent:isFatalEvent]) {
770775
// Remove some mutable properties from the device/app contexts which are no longer
771776
// applicable
772-
[self removeExtraDeviceContextFromEvent:event];
777+
[self removeExtraDeviceContextFromEvent:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)];
773778
} else if (!isFatalEvent) {
774779
// Store the current free memory battery level and more mutable properties,
775780
// at the time of this event, but not for crashes as the current data isn't guaranteed to be
776781
// the same as when the app crashed.
777-
[self applyExtraDeviceContextToEvent:event];
778-
[self applyCultureContextToEvent:event];
782+
[self applyExtraDeviceContextToEvent:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)];
783+
[self applyCultureContextToEvent:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)];
779784
#if SENTRY_HAS_UIKIT
780-
[self applyCurrentViewNamesToEventContext:event withScope:scope];
785+
[self applyCurrentViewNamesToEventContext:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)
786+
withScope:scope];
781787
#endif // SENTRY_HAS_UIKIT
782788
}
783789

@@ -788,7 +794,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
788794
}
789795

790796
// Need to do this after the scope is applied cause this sets the user if there is any
791-
[self setUserIdIfNoUserSet:event];
797+
[self setUserIdIfNoUserSet:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)];
792798

793799
BOOL eventIsATransaction
794800
= event.type != nil && [event.type isEqualToString:SentryEnvelopeItemTypes.transaction];
@@ -822,7 +828,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
822828
}
823829

824830
if (eventIsNotUserFeedback && event != nil && nil != self.options.beforeSend) {
825-
event = self.options.beforeSend(event);
831+
event = self.options.beforeSend(SENTRY_UNWRAP_NULLABLE(SentryEvent, event));
826832
if (event == nil) {
827833
[self recordLost:eventIsNotATransaction reason:kSentryDiscardReasonBeforeSend];
828834
if (eventIsATransaction) {
@@ -843,7 +849,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
843849
if (event != nil) {
844850
// if the event is dropped by beforeSend we should not execute event processors as they
845851
// might trigger e.g. unnecessary replay capture
846-
event = [self callEventProcessors:event];
852+
event = [self callEventProcessors:SENTRY_UNWRAP_NULLABLE(SentryEvent, event)];
847853
if (event == nil) {
848854
[self recordLost:eventIsNotATransaction reason:kSentryDiscardReasonEventProcessor];
849855
if (eventIsATransaction) {
@@ -866,7 +872,7 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event
866872
// We only want to call the callback once. It can occur that multiple crash events are
867873
// about to be sent.
868874
SentrySDKInternal.crashedLastRunCalled = YES;
869-
self.options.onCrashedLastRun(event);
875+
self.options.onCrashedLastRun(SENTRY_UNWRAP_NULLABLE(SentryEvent, event));
870876
}
871877

872878
return event;
@@ -926,7 +932,7 @@ - (void)setSdk:(SentryEvent *)event
926932
event.sdk = [[[SentrySdkInfo alloc] initWithOptions:self.options] serialize];
927933
}
928934

929-
- (void)setUserInfo:(NSDictionary *)userInfo withEvent:(SentryEvent *)event
935+
- (void)setUserInfo:(NSDictionary *_Nullable)userInfo withEvent:(SentryEvent *_Nullable)event
930936
{
931937
if (nil != event && nil != userInfo && userInfo.count > 0) {
932938
NSMutableDictionary *context;
@@ -989,14 +995,23 @@ - (void)applyExtraDeviceContextToEvent:(SentryEvent *)event
989995
[self modifyContext:event
990996
key:SENTRY_CONTEXT_DEVICE_KEY
991997
block:^(NSMutableDictionary *device) {
992-
[device addEntriesFromDictionary:extraContext[SENTRY_CONTEXT_DEVICE_KEY]];
998+
if (extraContext[SENTRY_CONTEXT_DEVICE_KEY] != nil &&
999+
[extraContext[SENTRY_CONTEXT_DEVICE_KEY]
1000+
isKindOfClass:NSDictionary.class]) {
1001+
[device addEntriesFromDictionary:extraContext[SENTRY_CONTEXT_DEVICE_KEY]
1002+
?: @ {}];
1003+
}
9931004
}];
9941005

995-
[self modifyContext:event
996-
key:@"app"
997-
block:^(NSMutableDictionary *app) {
998-
[app addEntriesFromDictionary:extraContext[@"app"]];
999-
}];
1006+
[self
1007+
modifyContext:event
1008+
key:SENTRY_CONTEXT_APP_KEY
1009+
block:^(NSMutableDictionary *app) {
1010+
if (extraContext[SENTRY_CONTEXT_APP_KEY] != nil &&
1011+
[extraContext[SENTRY_CONTEXT_APP_KEY] isKindOfClass:NSDictionary.class]) {
1012+
[app addEntriesFromDictionary:extraContext[SENTRY_CONTEXT_APP_KEY] ?: @ {}];
1013+
}
1014+
}];
10001015
}
10011016

10021017
#if SENTRY_HAS_UIKIT

0 commit comments

Comments
 (0)