<commit_before>package im.tny.segvault.disturbances;

import android.content.Context;

import com.evernote.android.job.JobManager;

import java.util.Date;

import io.realm.DynamicRealm;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmMigration;
import io.realm.RealmSchema;

/**
 * Created by gabriel on 4/14/17.
 */

public class Application extends android.support.multidex.MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        LocaleUtil.initializeLocale(getApplicationContext());
        StethoUtils.install(this);
        initRealm(this);
        JobManager.create(this).addJobCreator(new OurJobCreator());
    }

    @Override
    public Context getApplicationContext() {
        Context context = super.getApplicationContext();
        LocaleUtil.initializeLocale(context);
        return context;
    }

    public static void initRealm(Context context) {
        // Initialize Realm. Should only be done once when the application starts.
        Realm.init(context);
        RealmConfiguration config = new RealmConfiguration.Builder()
                .schemaVersion(8) // Must be bumped when the schema changes
                .migration(new MyMigration())
                .build();
        Realm.setDefaultConfiguration(config);
    }

    public static Realm getDefaultRealmInstance(Context context) {
        Realm realm;
        try {
            realm = Realm.getDefaultInstance();
        } catch (IllegalStateException e) {
            Application.initRealm(context);
            realm = Realm.getDefaultInstance();
        }
        return realm;<commit_msg>Fix crash on app start due to corrupt Realm<commit_after>package im.tny.segvault.disturbances;

import android.content.Context;

import com.evernote.android.job.JobManager;

import java.util.Date;

import io.realm.DynamicRealm;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmMigration;
import io.realm.RealmSchema;
import io.realm.exceptions.RealmFileException;

/**
 * Created by gabriel on 4/14/17.
 */

public class Application extends android.support.multidex.MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        LocaleUtil.initializeLocale(getApplicationContext());
        StethoUtils.install(this);
        initRealm(this);
        JobManager.create(this).addJobCreator(new OurJobCreator());
    }

    @Override
    public Context getApplicationContext() {
        Context context = super.getApplicationContext();
        LocaleUtil.initializeLocale(context);
        return context;
    }

    public static void initRealm(Context context) {
        // Initialize Realm. Should only be done once when the application starts.
        Realm.init(context);
        RealmConfiguration config = new RealmConfiguration.Builder()
                .schemaVersion(8) // Must be bumped when the schema changes
                .migration(new MyMigration())
                .build();
        Realm.setDefaultConfiguration(config);
    }

    public static Realm getDefaultRealmInstance(Context context) {
        Realm realm;
        try {
            realm = Realm.getDefaultInstance();
        } catch (IllegalStateException e) {
            Application.initRealm(context);
            realm = Realm.getDefaultInstance();
        } catch (RealmFileException e) {
            // happens when the DB is corrupted
            Application.initRealm(context);
            realm = Realm.getDefaultInstance();
        }
        return realm;
{'fraction_non_alphanumeric': 0.09006734006734007, 'fraction_numerical': 0.003367003367003367, 'mean_word_length': 2.744747899159664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1087153', 'n_tokens_mistral': 963, 'n_tokens_neox': 950, 'n_words': 219}