[Demonstration 1]

[Buggy Method]
private Query query(Map<String, Object> criteria, int limit, String querySql) {
    Session session = connector.getSessionFactory().openSession();
    Query query = session.createQuery("from " + this.entityName + " s where " + querySql);
    for (Object key : criteria.keySet()) {
        if (criteria.get(key) != null) {
            query.setParameter(key.toString(), criteria.get(key));
        }
    }
    session.flush();
    session.clear();
    session.close();
    query.setMaxResults(limit);
    return query;
}

[Buggy Hunk]
Session session =  connector.getSessionFactory().openSession();

[Patch]
Session session =  connector.getSession();

[Demonstration 2]

[Buggy Method]
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    selectedMenuItem = item;
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    if (id == R.id.nav_courseSchedule) {
        ScheduleFragment scheduleFragment = new ScheduleFragment();
        replaceWithFragment(scheduleFragment);
    } else {
        Bundle args = new Bundle();
        if (id == R.id.nav_recentActivities) {
            args.putSerializable(PageFragment.ARG_ITEM_TYPE, FeedItemsContract.TYPES.RECENT_ACTIVITIES);
        } else if (id == R.id.nav_news) {
            args.putSerializable(PageFragment.ARG_ITEM_TYPE, FeedItemsContract.TYPES.NEWS);
        } else if (id == R.id.nav_tickets) {
            args.putSerializable(PageFragment.ARG_ITEM_TYPE, FeedItemsContract.TYPES.TICKET);
        } else if (id == R.id.nav_sales) {
            args.putSerializable(PageFragment.ARG_ITEM_TYPE, FeedItemsContract.TYPES.SALES);
        }
        PageFragment pageFragment = new PageFragment();
        pageFragment.setArguments(args);
        replaceWithFragment(pageFragment);
    }
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(item.getTitle());
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

[Buggy Hunk]
args.putSerializable(PageFragment.ARG_ITEM_TYPE, FeedItemsContract.TYPES.TICKET);

[Patch]
args.putSerializable(PageFragment.ARG_ITEM_TYPE, FeedItemsContract.TYPES.TICKETS);

[Demonstration 3]

[Buggy Method]
protected void handleRequests(final Protocol p) throws IOException {
    try {
        while (!Thread.interrupted()) {
            final String msg;
            try {
                // get the real message that was send
                msg = p.waitForMessage();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Retrieved query '" + msg + "'.");
                }
            } catch (final WrappedException e) {
                /*
					 * The client send an exception, we can just log it here.
					 * All other exception (not send just occurring) are serious
					 * enough to close the connection completely.
					 */
                if (LOG.isErrorEnabled()) {
                    LOG.error("Client send exception '" + e.getMessage() + "'", e);
                }
                /*
					 * Read the next one, the client will close the connection
					 * if the error is serious.
					 */
                continue;
            }
            try {
                // parse the query and send the type
                final IQuery query = queryFactory.parseQuery(msg);
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Writing queryType of '" + msg + "' as '" + query.getQueryType() + "'.");
                }
                p.writeQueryType(query.getQueryType());
                // check the status
                final QueryStatus status = p.readQueryStatus();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Got queryStatus '" + status + "' from client for query '" + msg + "'.");
                }
                // cancel if wished for
                if (QueryStatus.CANCEL.equals(status)) {
                    p.writeEndOfResponse();
                    continue;
                }
                // enable identifier collection if needed
                final boolean enableIdCollection = QueryStatus.PROCESSANDGETIDS.equals(status);
                query.enableIdCollection(enableIdCollection);
                // retrieve the result
                try {
                    final IQueryResult res = queryFactory.evaluateQuery(query, new ClientResourceResolver(p));
                    // write the identifiers of not canceled
                    if (checkCancellation(p)) {
                        continue;
                    } else if (enableIdCollection && writeIdentifiers(p, res.getCollectedIds())) {
                        continue;
                    }
                    /*
						 * All the methods return true if the process was
						 * cancelled, therefore check the pre-requirements and
						 * the result of execution.
						 */
                    if (checkCancellation(p)) {
                        continue;
                    } else if (res instanceof IQueryResultSingleInteger && writeSingleInteger(p, msg, (IQueryResultSingleInteger) res)) {
                        continue;
                    } else if (res instanceof IQueryResultSet && writeSet(p, msg, (IQueryResultSet) res)) {
                        continue;
                    }
                } catch (final CancellationException e) {
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Handling of '" + msg + "' was canceled during evaluation.");
                    }
                    p.writeEndOfResponse();
                    continue;
                }
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Answer of '" + msg + "' sent, sending eor.");
                }
                p.writeEndOfResponse();
            } catch (final SocketException e) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("SocketException while handling '" + msg + "' sending '" + e.getMessage() + "'.");
                }
            } catch (final PermissionException e) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("User tried to execute an invalid operation.", e);
                }
                p.writeException(e);
            } catch (final Exception e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("Exception while handling '" + msg + "' sending '" + e.getMessage() + "'.");
                }
                p.writeException(e);
            }
        }
    } catch (final EOFException e) {
        // indicates that the stream was just closed
    }
}

[Buggy Hunk]
+ "' sending '" + e.getMessage() + "'.");

[Patch]
+ "' sending '" + e.getMessage() + "'.", e);