From 144ab8910da96e23f8c8ab4407da5b2c05e49e9a Mon Sep 17 00:00:00 2001 From: Austin Zheng Date: Fri, 23 Sep 2016 16:45:28 -0700 Subject: [PATCH] Fix a bug uncovered while writing tests `[handle sessionStillExists]` returns NO if `handle` is `nil`. In this case the session handle shouldn't be considered invalid, since it hasn't yet been registered in the first place. --- Realm/RLMSyncSession_Private.h | 2 ++ Realm/RLMSyncUser.mm | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Realm/RLMSyncSession_Private.h b/Realm/RLMSyncSession_Private.h index 10538117dc..63c1da8532 100644 --- a/Realm/RLMSyncSession_Private.h +++ b/Realm/RLMSyncSession_Private.h @@ -62,6 +62,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) NSTimer *refreshTimer; +- (nullable RLMSyncSessionHandle *)sessionHandle; + - (void)configureWithAccessToken:(RLMServerToken)token expiry:(NSTimeInterval)expiry user:(RLMSyncUser *)user diff --git a/Realm/RLMSyncUser.mm b/Realm/RLMSyncUser.mm index 8a1e2b20f1..8e0acb8116 100644 --- a/Realm/RLMSyncUser.mm +++ b/Realm/RLMSyncUser.mm @@ -33,10 +33,6 @@ using namespace realm; -@interface RLMSyncSession () -- (id)sessionHandle; -@end - @interface RLMSyncUser () - (instancetype)initWithAuthServer:(nullable NSURL *)authServer NS_DESIGNATED_INITIALIZER; @@ -113,10 +109,11 @@ - (void)logOut { - (nullable RLMSyncSession *)sessionForURL:(NSURL *)url { RLMSyncSession *session = [self.sessionsStorage objectForKey:url]; - if (![[session sessionHandle] sessionStillExists]) { + RLMSyncSessionHandle *handle = [session sessionHandle]; + if (handle && ![handle sessionStillExists]) { [self.sessionsStorage removeObjectForKey:url]; return nil; - } else if ([[session sessionHandle] sessionIsInErrorState]) { + } else if ([handle sessionIsInErrorState]) { [session _invalidate]; return nil; }