[Demonstration 1]

[Buggy Method]
public void newVersionCheck() {
    int prev_version = PrefKey.CURRENT_VERSION.getInt(-1);
    int current_version = CommonCommands.getVersionNumber(this);
    boolean showImportantUpgradeInfo = false;
    if (prev_version < current_version) {
        if (prev_version == -1) {
            return;
        }
        PrefKey.CURRENT_VERSION.putInt(current_version);
        SharedPreferences settings = MyApplication.getInstance().getSettings();
        Editor edit = settings.edit();
        if (prev_version < 19) {
            edit.putString(PrefKey.SHARE_TARGET.getKey(), settings.getString("ftp_target", ""));
            edit.remove("ftp_target");
            edit.apply();
        }
        if (prev_version < 28) {
            Log.i("MyExpenses", String.format("Upgrading to version 28: Purging %d transactions from datbase", getContentResolver().delete(TransactionProvider.TRANSACTIONS_URI, KEY_ACCOUNTID + " not in (SELECT _id FROM accounts)", null)));
        }
        if (prev_version < 30) {
            if (!"".equals(PrefKey.SHARE_TARGET.getString(""))) {
                edit.putBoolean(PrefKey.SHARE_TARGET.getKey(), true);
                edit.apply();
            }
        }
        if (prev_version < 40) {
            //this no longer works since we migrated time to utc format
            //  DbUtils.fixDateValues(getContentResolver());
            //we do not want to show both reminder dialogs too quickly one after the other for upgrading users
            //if they are already above both tresholds, so we set some delay
            edit.putLong("nextReminderContrib", Transaction.getSequenceCount() + 23);
            edit.apply();
        }
        if (prev_version < 163) {
            edit.remove("qif_export_file_encoding");
            edit.apply();
        }
        if (prev_version < 199) {
            //filter serialization format has changed
            for (Map.Entry<String, ?> entry : settings.getAll().entrySet()) {
                String key = entry.getKey();
                String[] keyParts = key.split("_");
                if (keyParts[0].equals("filter")) {
                    String val = settings.getString(key, "");
                    switch(keyParts[1]) {
                        case "method":
                        case "payee":
                        case "cat":
                            int sepIndex = val.indexOf(";");
                            edit.putString(key, val.substring(sepIndex + 1) + ";" + Criteria.escapeSeparator(val.substring(0, sepIndex)));
                            break;
                        case "cr":
                            edit.putString(key, Transaction.CrStatus.values()[Integer.parseInt(val)].name());
                            break;
                    }
                }
            }
            edit.apply();
        }
        if (prev_version < 202) {
            String appDir = PrefKey.APP_DIR.getString(null);
            if (appDir != null) {
                PrefKey.APP_DIR.putString(Uri.fromFile(new File(appDir)).toString());
            }
        }
        if (prev_version < 221) {
            PrefKey.SORT_ORDER_LEGACY.putString(PrefKey.CATEGORIES_SORT_BY_USAGES_LEGACY.getBoolean(true) ? "USAGES" : "ALPHABETIC");
        }
        VersionDialogFragment.newInstance(prev_version, showImportantUpgradeInfo).show(getSupportFragmentManager(), "VERSION_INFO");
    } else {
        if (ContribFeature.SYNCHRONIZATION.usagesLeft() < 1 && !PrefKey.SYNC_UPSELL_NOTIFICATION_SHOWN.getBoolean(false)) {
            PrefKey.SYNC_UPSELL_NOTIFICATION_SHOWN.putBoolean(true);
            ContribUtils.showContribNotification(this, ContribFeature.SYNCHRONIZATION);
        }
    }
    checkCalendarPermission();
}

[Buggy Hunk]
if (ContribFeature.SYNCHRONIZATION.usagesLeft() < 1 &&

[Patch]
if (!ContribFeature.SYNCHRONIZATION.hasAccess() && ContribFeature.SYNCHRONIZATION.usagesLeft() < 1 &&

[Demonstration 2]

[Buggy Method]
public User getUserByEmail(String inEmail) {
    User target = null;
    Data record = (Data) searchByField("email", inEmail);
    if (record != null) {
        target = (User) loadData(record);
    }
    return target;
}

[Buggy Hunk]
Data record = (Data)searchByField("email", inEmail);

[Patch]
Data record = (Data)query().exact("email", inEmail).searchOne();

[Demonstration 3]

[Buggy Method]
@SuppressWarnings("unchecked")
@Override
public <R> R getResults(Class<? extends R> type) {
    if (type.equals(String.class)) {
        return (R) (value.toString());
    } else if (type.equals(Long.class)) {
        return (R) value;
    } else {
        return null;
    }
}

[Buggy Hunk]
} else if (type.equals(Long.class)) {

[Patch]
} else if (type.equals(Double.class)) {