[Demonstration 1]

[Buggy Method]
@Override
public void run() {
    TransactionManager tm = GraphDbHandlerForJTA.getInstance().getTransactionManager();
    try {
        tm.begin();
    } catch (NotSupportedException | SystemException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return;
    }
    try {
        final EntityManager em = GraphDbHandlerForJTA.getInstance().getEntityManagerFactory().createEntityManager();
        Tag firstTag = new Tag();
        firstTag.setName("First");
        em.persist(firstTag);
        Tag secondTag = new Tag();
        secondTag.setName("Second");
        em.persist(secondTag);
        Formula form1 = new Formula();
        form1.setName("Form1");
        form1.setDescription("First test formula");
        form1.addTag(firstTag);
        form1.addTag(secondTag);
        em.persist(form1);
        Formula form2 = new Formula();
        form2.setName("Form2");
        form2.setDescription("Second test formula");
        form2.addTag(firstTag);
        em.persist(form2);
        Formula form3 = new Formula();
        form3.setName("Form3");
        form3.setDescription("Third test formula");
        em.persist(form3);
        Formula form4 = new Formula();
        form4.setName("Form4");
        form4.setDescription("Fourth test formula");
        em.persist(form4);
        // Add relationships
        form1.addIngredient(form3, "50%");
        form2.addIngredient(form4, "10%");
        form2.addIngredient(form1, "50%");
        em.persist(form1);
        em.persist(form4);
        em.flush();
        em.close();
        try {
            tm.commit();
            System.out.println("stored");
        } catch (SecurityException | IllegalStateException | RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } catch (PersistenceException pe) {
        if (pe.getCause() instanceof EntityAlreadyExistsException) {
            System.out.println(pe.getMessage());
        } else {
            pe.printStackTrace();
        }
        try {
            tm.rollback();
            System.out.println("Transaction rolled back");
        } catch (IllegalStateException | SecurityException | SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

[Buggy Hunk]
final EntityManager em = GraphDbHandlerForJTA.getInstance().getEntityManagerFactory().createEntityManager();

[Patch]
final EntityManager em = GraphDbHandlerForJTA.getInstance().createNewEntityManager();

[Demonstration 2]

[Buggy Method]
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    int count = 0;
    String podcastId;
    SharedPreferences prefs = getContext().getSharedPreferences("internals", Context.MODE_WORLD_READABLE);
    Long activePodcastId = prefs.getLong(PREF_ACTIVE, -1);
    switch(uriMatcher.match(uri)) {
        case PODCAST_ID:
            podcastId = uri.getLastPathSegment();
            break;
        case PODCASTS_ACTIVE:
            if (values.containsKey(COLUMN_ID)) {
                activePodcastId = values.getAsLong(COLUMN_ID);
                Editor editor = prefs.edit();
                if (activePodcastId != null)
                    editor.putLong(PREF_ACTIVE, values.getAsLong(COLUMN_ID));
                else
                    editor.remove(PREF_ACTIVE);
                editor.commit();
                // if we're clearing the active podcast or updating just the ID, don't go to the DB
                if (activePodcastId == null || values.size() == 1)
                    return 0;
            }
            // if we don't have an active podcast, don't update it
            if (activePodcastId == -1)
                return 0;
            podcastId = String.valueOf(activePodcastId);
            break;
        default:
            throw new IllegalArgumentException("Unknown URI");
    }
    String extraWhere = COLUMN_ID + " = " + podcastId;
    if (where != null)
        where = extraWhere + " AND " + where;
    else
        where = extraWhere;
    // subscription title is not in the table
    values.remove(COLUMN_SUBSCRIPTION_TITLE);
    // update queuePosition separately
    if (values.containsKey(COLUMN_QUEUE_POSITION)) {
        // get the new position
        Integer newPosition = values.getAsInteger(COLUMN_QUEUE_POSITION);
        values.remove(COLUMN_QUEUE_POSITION);
        // no way to get changed record count until
        // SQLiteStatement.executeUpdateDelete in API level 11
        updateQueuePosition(podcastId, newPosition);
    }
    SQLiteDatabase db = _dbAdapter.getWritableDatabase();
    if (values.size() > 0)
        count += db.update("podcasts", values, where, whereArgs);
    getContext().getContentResolver().notifyChange(uri, null);
    if (values.containsKey(COLUMN_FILE_SIZE))
        getContext().getContentResolver().notifyChange(Uri.withAppendedPath(URI, "to_download"), null);
    if (podcastId.equals(activePodcastId))
        getContext().getContentResolver().notifyChange(Uri.withAppendedPath(URI, "active"), null);
    return count;
}

[Buggy Hunk]
getContext().getContentResolver().notifyChange(uri, null);

[Patch]
getContext().getContentResolver().notifyChange(Uri.withAppendedPath(URI, podcastId), null);

[Demonstration 3]

[Buggy Method]
@NonNull
@Override
protected Result onRunJob(Params params) {
    App.getComponent().inject(this);
    preferencesRepo.getCurrentCity().flatMap(dbRepo::getCity).zipWith(preferencesRepo.getCurrentCity().flatMap(remoteRepo::getWeather), DBConverter::fromRawWeatherData).flatMap(dbRepo::insertOrUpdateWeather).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::sendWeatherNotification);
    return Result.SUCCESS;
}

[Buggy Hunk]
.subscribe(this::sendWeatherNotification);

[Patch]
.subscribe(this::sendWeatherNotification, this::handleError);