[Demonstration 1]

[Buggy Method]
@Override
public <T> T updateI(final Transaction txn, final Cache cache, final T bean, final Object id) throws UnsupportedOperationException, IllegalStateException, IllegalArgumentException, TransactionException, NotFoundException, KeyViolationException, DataConstraintViolationException, OperationTimeoutException, NotEnoughResourceException, DataProviderException {
    final Class<?> type = bean.getClass();
    final StorableInfo sinfo = EntityUtils.info(type);
    final String tableName = parseTableName(DEFAULT_TARGET_NAME, sinfo);
    String setColumns = "";
    for (ElementInfo einfo : sinfo.elements()) {
        if (!einfo.virtual()) {
            if (StringValidations.isValid(setColumns))
                setColumns = setColumns + ", ";
            setColumns = setColumns + parseColumnName(einfo) + "=?";
        }
    }
    final String where = parseColumnName(sinfo.surrogateKey()) + "=?";
    final String sql = String.format(SQL_UPDATE, tableName, setColumns, where);
    final Connection conn = getConnection(txn);
    try {
        final PreparedStatement pst = conn.prepareStatement(sql);
        setQueryTimeout(pst);
        // Columns values
        int parameterIndex = 1;
        for (ElementInfo einfo : sinfo.elements()) {
            if (!einfo.virtual()) {
                Object value = EntityUtils.value(bean, einfo.name());
                if (value == null) {
                    pst.setObject(parameterIndex++, value);
                } else if (value instanceof TimeUnit) {
                    String unit = EntityUtils.parseTimeUnit((TimeUnit) value);
                    pst.setObject(parameterIndex++, unit);
                } else if (value instanceof Enum<?>) {
                    pst.setObject(parameterIndex++, value.toString());
                } else if (value instanceof Date && einfo.dataType() == DataType.DATE) {
                    Timestamp ts = new Timestamp(((Date) value).getTime());
                    pst.setTimestamp(parameterIndex++, ts);
                } else if (value instanceof Date && einfo.dataType() == DataType.LONG) {
                    Long tmp = ((Date) value).getTime();
                    pst.setLong(parameterIndex++, tmp);
                } else
                    pst.setObject(parameterIndex++, value);
            }
        }
        // Where column value
        pst.setObject(parameterIndex++, id);
        int affectedRows = pst.executeUpdate();
        pst.close();
        commit(txn, conn);
        if (affectedRows == 0)
            throw new NotFoundException("The surrogate key did not match any bean");
        // Updates the cache
        cacheIt(txn, cache, bean);
    } catch (final SQLTimeoutException sqle) {
        String msg = "The currently executing 'updateI' operation is timed out";
        try {
            rollback(txn, conn);
        } catch (final SQLException e) {
            msg = msg + " and could not roll back the transaction; there can be inconsistencies";
            sqle.setNextException(e);
        }
        throw new OperationTimeoutException(msg, sqle);
    } catch (final SQLException sqle) {
        // FIXME support sql state 23502 (not null constraint fails)
        String msg = sqle.getSQLState().startsWith("23") ? MESSAGE_KEY_VIOLATION : "Could not execute the database statement";
        try {
            rollback(txn, conn);
        } catch (final SQLException e) {
            msg = msg + " and could not roll back the transaction; there can be inconsistencies";
            sqle.setNextException(e);
        }
        if (// NOT NULL FAIL
        sqle.getSQLState().equals("23502"))
            throw new DataConstraintViolationException(msg, sqle);
        else if (sqle.getSQLState().startsWith("23"))
            throw new KeyViolationException(msg, sqle);
        else
            throw new DataProviderException(msg, sqle);
    } finally {
        close(txn, conn);
    }
    return bean;
}

[Buggy Hunk]
final Class<?> type = bean.getClass();

[Patch]
final Class<T> type = (Class<T>) bean.getClass();

[Demonstration 2]

[Buggy Method]
public Span[] sentPosDetect(String s) {
    List<Span> sentences = new ArrayList<Span>();
    int start = 0;
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c == '\n' || c == '\r') {
            if (start - i > 0) {
                Span span = new Span(start, i).trim(s);
                if (span.length() > 0) {
                    sentences.add(span);
                }
                start = i + 1;
            }
        }
    }
    if (s.length() - start > 0) {
        Span span = new Span(start, s.length()).trim(s);
        if (span.length() > 0) {
            sentences.add(span);
        }
    }
    return sentences.toArray(new Span[sentences.size()]);
}

[Buggy Hunk]
if (start - i > 0) {

[Patch]
if (i - start > 0) {

[Demonstration 3]

[Buggy Method]
private static <T extends Type> Set<T> filterTypes(Collection<T> types, BiPredicate<Type, Type> potentialFilter, BiPredicate<Type, Type> existingFilter) {
    if (types.isEmpty()) {
        // Fast track trivial cases
        return Collections.emptySet();
    }
    if (types.size() == 1) {
        // Fast track trivial cases
        return Collections.singleton(types.iterator().next());
    }
    // Discard any member that is a super type of another
    final Set<T> filteredTypes = new HashSet<>();
    potentialCandidates: for (T potentialCandidate : types) {
        for (Iterator<T> iterator = filteredTypes.iterator(); iterator.hasNext(); ) {
            final T existingCandidate = iterator.next();
            if (potentialFilter.test(potentialCandidate, existingCandidate)) {
                // potential candidate is filtered for existing one, don't add
                continue potentialCandidates;
            } else if (existingFilter.test(potentialCandidate, existingCandidate)) {
                // existing candidate is filtered for potential one, remove it
                iterator.remove();
            }
        }
        filteredTypes.add(potentialCandidate);
    }
    return filteredTypes;
}

[Buggy Hunk]
final Set<T> filteredTypes = new HashSet<>();

[Patch]
final Set<T> filteredTypes = new LinkedHashSet<>();