[Demonstration 1]

[Buggy Method]
@Override
public boolean computeSlots() {
    // What's the minimum number of map and reduce slots we should try to
    // launch?
    mapSlots = 0;
    reduceSlots = 0;
    // Determine how many slots we can allocate.
    int slots = mapSlotsMax + reduceSlotsMax;
    slots = (int) Math.min(slots, (cpus - containerCpus) / slotCpus);
    slots = (int) Math.min(slots, (mem - containerMem) / slotMem);
    slots = (int) Math.min(slots, (disk - containerDisk) / slotDisk);
    // Is this offer too small for even the minimum slots?
    if (slots < 1) {
        return false;
    }
    // Is the number of slots we need sufficiently small? If so, we can
    // allocate exactly the number we need.
    if (slots >= neededMapSlots + neededReduceSlots && neededMapSlots < mapSlotsMax && neededReduceSlots < reduceSlotsMax) {
        mapSlots = neededMapSlots;
        reduceSlots = neededReduceSlots;
    } else {
        // Allocate slots fairly for this resource offer.
        double mapFactor = (double) neededMapSlots / (neededMapSlots + neededReduceSlots);
        double reduceFactor = (double) neededReduceSlots / (neededMapSlots + neededReduceSlots);
        // To avoid map/reduce slot starvation, don't allow more than 50%
        // spread between map/reduce slots when we need both mappers and
        // reducers.
        if (neededMapSlots > 0 && neededReduceSlots > 0) {
            if (mapFactor < 0.25) {
                mapFactor = 0.25;
            } else if (mapFactor > 0.75) {
                mapFactor = 0.75;
            }
            if (reduceFactor < 0.25) {
                reduceFactor = 0.25;
            } else if (reduceFactor > 0.75) {
                reduceFactor = 0.75;
            }
        }
        mapSlots = Math.min(Math.min((long) Math.round(mapFactor * slots), mapSlotsMax), neededMapSlots);
        // The remaining slots are allocated for reduces.
        slots -= mapSlots;
        reduceSlots = Math.min(Math.min(slots, reduceSlotsMax), neededReduceSlots);
    }
    return true;
}

[Buggy Hunk]
mapSlots = Math.min(Math.min((long)Math.round(mapFactor * slots), mapSlotsMax), neededMapSlots);

[Patch]
mapSlots = Math.min(Math.min((long)Math.max(Math.round(mapFactor * slots), 1), mapSlotsMax), neededMapSlots);

[Demonstration 2]

[Buggy Method]
public static int matchingChars(String s1, String s2) {
    if (s1.length() > s2.length()) {
        return matchingChars(s2, s1);
    }
    int s1StartIndex = 0;
    int s2StartIndex = s2.indexOf(s1.charAt(s1StartIndex));
    while (s2StartIndex == -1 && s1StartIndex < s1.length()) {
        s1StartIndex++;
        s2StartIndex = s2.indexOf(s1.charAt(s1StartIndex));
    }
    if (s2StartIndex > -1) {
        int returned = 0;
        for (int i = s1StartIndex; i < s1.length() && i - s1StartIndex + s2StartIndex < s2.length(); i++) {
            if (s1.charAt(i) == s2.charAt(i - s1StartIndex + s2StartIndex)) {
                returned++;
            }
        }
        return returned;
    }
    return 0;
}

[Buggy Hunk]
while (s2StartIndex == -1 && s1StartIndex < s1.length()) {

[Patch]
while (s2StartIndex == -1 && s1StartIndex < s1.length() - 1) {

[Demonstration 3]

[Buggy Method]
public static long calculateDays(long start, long end, int[] filterWeekdays) {
    if (filterWeekdays == null) {
        final long days = (long) FloatMath.ceil((end - start) / (float) CalendarUtils.DAY_IN_MILLIS);
        Logger.debug("(end(%d, %s) - start(%d, %s)) / dayInMillis(%d) = days(%d)", end, CalendarUtils.timeToReadableString(end), start, CalendarUtils.timeToReadableString(start), CalendarUtils.DAY_IN_MILLIS, days);
        return days;
    }
    long time = 0;
    start = CalendarUtils.getStartOfDay(start);
    end = CalendarUtils.getStartOfDay(end);
    Set<Integer> weekdays = new HashSet<Integer>();
    for (int fday : filterWeekdays) {
        weekdays.add((fday == 0 ? 7 : fday));
    }
    int weekday;
    long count = 0;
    for (time = start; time <= end; time += CalendarUtils.DAY_IN_MILLIS) {
        weekday = CalendarUtils.getWeekDay(time);
        Logger.debug("time = %s, weekday = %d", CalendarUtils.timeToReadableString(time), weekday);
        if (weekdays.contains(weekday)) {
            count++;
        }
    }
    return count;
}

[Buggy Hunk]
final long days = (long)FloatMath.ceil((end - start)

[Patch]
final long days = (long)Math.ceil((end - start)