<commit_before>package com.github.ayltai.newspaper.data;

import android.content.Context;
import android.support.annotation.NonNull;

import dagger.Module;
import dagger.Provides;
import io.realm.Realm;
import io.realm.RealmConfiguration;

@Module
public final class DataModule {
    private static final int SCHEMA_VERSION = 1;

    private static boolean isInitialized;

    private final Context context;

    public DataModule(@NonNull final Context context) {
        this.context = context.getApplicationContext();
    }

    @NonNull
    @Provides
    Context provideContext() {
        return this.context;
    }

    @NonNull
    @Provides
    Realm provideRealm() {
        if (!DataModule.isInitialized) {
            Realm.init(this.context);
            Realm.setDefaultConfiguration(new RealmConfiguration.Builder().schemaVersion(DataModule.SCHEMA_VERSION).build());

            DataModule.isInitialized = true;
        }

        return Realm.getDefaultInstance();
    }
}<commit_msg>Fix app crash due to Realm database migration<commit_after>package com.github.ayltai.newspaper.data;

import android.content.Context;
import android.support.annotation.NonNull;

import dagger.Module;
import dagger.Provides;
import io.realm.Realm;
import io.realm.RealmConfiguration;

@Module
public final class DataModule {
    private static final int SCHEMA_VERSION = 1;

    private static boolean isInitialized;

    private final Context context;

    public DataModule(@NonNull final Context context) {
        this.context = context.getApplicationContext();
    }

    @NonNull
    @Provides
    Context provideContext() {
        return this.context;
    }

    @NonNull
    @Provides
    Realm provideRealm() {
        if (!DataModule.isInitialized) {
            Realm.init(this.context);
            Realm.setDefaultConfiguration(new RealmConfiguration.Builder()
                .schemaVersion(DataModule.SCHEMA_VERSION)
                .deleteRealmIfMigrationNeeded()
                .compactOnLaunch()
                .build());

            DataModule.isInitialized = true;
        }

        return Realm.getDefaultInstance();
    }
}
{'fraction_non_alphanumeric': 0.08562121917170777, 'fraction_numerical': 0.0009306654257794323, 'mean_word_length': 2.8949275362318843, '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': '1695012', 'n_tokens_mistral': 594, 'n_tokens_neox': 584, 'n_words': 129}