Realm must not be nil
<p>I updated my app from Realm 0.9x но 2.0.x
Now I have a lot of bug reports from 8, 9 and 10 iOS devices on Crashlytics about fatal exception:</p>

<pre><code>Fatal Exception: RLMException
Realm must not be nil
</code></pre>

<p>Stack trace looks like this:</p>

<blockquote>
  <p>RLMObjectStore.mm line 81
  RLMGetObjects</p>
  
  <p>RLMObject.mm line 154
  +[RLMObject objectsInRealm:withPredicate:]</p>
  
  <p>RLMObject.mm line 146
  +[RLMObject objectsInRealm:where:args:]</p>
  
  <p>RLMObject.mm line 140
  +[RLMObject objectsInRealm:where:]</p>
  
  <p>Sessions.m line 88
  +[Sessions resultWithSessionsWhere:]</p>
  
  <p>Sessions.m line 128
  +[Sessions activeSession]</p>
  
  <p>Sessions.m line 102
  +[Sessions appLaunched]</p>
  
  <p>AppDelegate.m line 60
  -[AppDelegate application:didFinishLaunchingWithOptions:]</p>
</blockquote>

<p>I can't reproduce bug on debug environment. It touched around 30-40% of users (not at all), and I it looks like only old users are touched.</p>

<p>There is no realm object in this method:</p>

<pre><code>/**
 *  Create and returns Realm configuration for sessions database
 */
+(nonnull RLMRealmConfiguration*)realmConfigurationForSessions
{
    RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
    // Use the default directory, but replace the filename with the 'sessions.realm'
    config.fileURL = [NSURL
                  URLWithString:[[[config.fileURL.absoluteString stringByDeletingLastPathComponent]
                                      stringByAppendingPathComponent:@"sessions"]
                                     stringByAppendingPathExtension:@"realm"]];
    return config;
}

+(nullable RLMRealm*)realmForConfiguration:(nullable RLMRealmConfiguration*)config
{
    if (!config) {
        return nil;
    }
    NSError *error;
    // Open the Realm with the configuration
    RLMRealm *realm = [RLMRealm realmWithConfiguration:config
                                                 error:&amp;error];
    if (error) {
        DLog(@"error: %@", error.localizedDescription);
    }
    return realm;
}
</code></pre>

<p>Questions: 1) what is the cause of this strange issue? 2) how do I can properly handle error and nil realm value in this situation?</p>