[Demonstration 1]

[Buggy Method]
@Override
public void run() throws IOException {
    log.debug("Initializing output file");
    int mapped = 0;
    try (BufferedWriter writer = Files.newBufferedWriter(outputFile, Charset.defaultCharset())) {
        // Write the Wiggle track header to the output file
        TrackHeader header = new TrackHeader("wiggle_0");
        header.setName("Converted " + inputFile.getPath().getFileName());
        header.setDescription("Converted " + inputFile.getPath().getFileName());
        writer.write(header.toString());
        writer.newLine();
        // Process each chromosome in the assembly
        for (String chr : assembly) {
            log.debug("Processing chromosome " + chr);
            // Write the contig header to the output file
            writer.write("fixedStep chrom=" + chr + " start=1 step=1 span=1");
            writer.newLine();
            int start = 1;
            while (start < assembly.getChrLength(chr)) {
                int stop = Math.min(start + DEFAULT_CHUNK_SIZE - 1, assembly.getChrLength(chr));
                int length = stop - start + 1;
                int[] count = new int[length];
                Iterator<? extends Interval> it = inputFile.query(chr, start, stop);
                while (it.hasNext()) {
                    Interval entry = it.next();
                    int center;
                    if (nucleosomeSize == null || nucleosomeSize == -1) {
                        center = entry.center() - start;
                    } else {
                        center = entry.getStart() + nucleosomeSize - start;
                    }
                    // Only map if it is in the current chunk
                    if (start <= center && center <= stop) {
                        count[center]++;
                        mapped++;
                    }
                }
                // Write the average at each base pair to the output file
                for (int i = 0; i < count.length; i++) {
                    writer.write(Integer.toString(count[i]));
                    writer.newLine();
                }
                // Process the next chunk
                start = stop + 1;
            }
        }
    }
    log.info("Mapped " + mapped + " reads");
}

[Buggy Hunk]
count[center]++;

[Patch]
count[center-start]++;

[Demonstration 2]

[Buggy Method]
public static PhotoResource[] filterToPhotoResources(String[] urls) {
    for (PhotoService service : photoServices.values()) {
        if (Logger.isDebugEnabled()) {
            Logger.debug("Using service %1s to check url: %2s", service.getClass().getName(), Arrays.toString(urls));
        }
        String[] filteredUrls = service.filter(urls);
        Logger.debug("Found %1s", Arrays.toString(urls));
        if (filteredUrls != null) {
            PhotoResource[] tweetPhotos = new PhotoResource[filteredUrls.length];
            for (int i = 0; i < urls.length; i++) {
                tweetPhotos[i] = new PhotoResource(filteredUrls[i], service);
            }
            return tweetPhotos;
        }
    }
    return null;
}

[Buggy Hunk]
for (int i = 0; i < urls.length; i++) {

[Patch]
for (int i = 0; i < filteredUrls.length; i++) {

[Demonstration 3]

[Buggy Method]
private void appendNumber(long n) {
    if (n < 0) {
        buf[count++] = '-';
        n = -n;
    }
    int i = count;
    for (long limit = 10; n > limit && limit > 0; limit *= 10) {
        i++;
    }
    count = i + 1;
    do {
        buf[i--] = (byte) (n % 10 + '0');
        n /= 10;
    } while (n != 0);
}

[Buggy Hunk]
for (long limit = 10; n > limit && limit > 0; limit *= 10) {

[Patch]
for (long limit = 10; n >= limit && limit > 0; limit *= 10) {