[Demonstration 1]

[Buggy Method]
public List<Page> divideProcessIntoPages(Process process) {
    int pageSize = pageTable.getPageSize();
    if (process.getData().length == pageSize) {
        return new ArrayList<Page>(Arrays.asList(new Page(process.getData())));
    }
    if (process.getData().length < pageSize) {
        byte[] pageData = new byte[pageSize];
        fillPageWithEmptyBytes(pageData, pageSize);
        for (int i = 0; i < process.getData().length; i++) pageData[i] = process.getData()[i];
        return new ArrayList<Page>(Arrays.asList(new Page(pageData)));
    }
    byte[] processDataCopy = process.getData();
    List<Page> processPages = new ArrayList<>();
    int index = 0;
    while (index <= process.getData().length || index <= process.getData().length + pageSize) {
        processPages.add(new Page(getNextProcessBlock(Arrays.copyOfRange(processDataCopy, index, index + pageSize))));
        index += pageSize;
    }
    return processPages;
}

[Buggy Hunk]
while (index<=process.getData().length || index<=process.getData().length + pageSize) {

[Patch]
while (index<process.getData().length) {

[Demonstration 2]

[Buggy Method]
public static void setBlocks(List<BlockData> blocks, Location center, int xRadius, int yRadius, int zRadius) {
    if (blocks == null) {
        throw new IllegalArgumentException("blocks cannot be null.");
    }
    if (blocks.size() != (xRadius * 2) * (yRadius * 2) * (zRadius * 2)) {
        throw new RuntimeException("blocks is not the correct length.");
    }
    if (center == null) {
        throw new IllegalArgumentException("center cannot be null.");
    }
    int minX = center.getBlockX() - xRadius;
    int maxX = center.getBlockX() + xRadius;
    int minY = center.getBlockY() - yRadius;
    int maxY = center.getBlockY() + yRadius;
    int minZ = center.getBlockZ() - zRadius;
    int maxZ = center.getBlockZ() + zRadius;
    Location currentLocation = new Location(center.getWorld(), 0.0d, 0.0d, 0.0d);
    int i = 0;
    for (int x = minX; x <= maxX; x++) {
        currentLocation.setX(x);
        for (int z = minZ; z <= maxZ; z++) {
            currentLocation.setZ(z);
            for (int y = minY; y <= maxY; y++) {
                currentLocation.setY(y);
                setBlock(currentLocation, blocks.get(i));
                i++;
            }
        }
    }
}

[Buggy Hunk]
if (blocks.size() != (xRadius * 2) * (yRadius * 2) * (zRadius * 2)) {

[Patch]
if (blocks.size() != (xRadius * 2 + 1) * (yRadius * 2 + 1) * (zRadius * 2 + 1)) {

[Demonstration 3]

[Buggy Method]
public int writeVirtualMemory(int vaddr, byte[] data, int offset, int length) {
    Lib.assertTrue(offset >= 0 && length >= 0 && offset + length <= data.length);
    byte[] memory = Machine.processor().getMemory();
    int vpn = Processor.pageFromAddress(vaddr);
    int ppn = getPPN(vpn, true);
    if (ppn < 0)
        return 0;
    int pageOffset = Processor.offsetFromAddress(vaddr);
    int paddr = Processor.makeAddress(ppn, pageOffset);
    int res = Math.min(length, pageSize - pageOffset);
    System.arraycopy(data, offset, memory, vaddr, res);
    while (length > res) {
        vpn++;
        ppn = getPPN(vpn, true);
        if (ppn < 0)
            return res;
        paddr = Processor.makeAddress(ppn, 0);
        int amount = Math.min(length - res, pageSize);
        System.arraycopy(data, offset + res, memory, paddr, amount);
        res += amount;
    }
    return res;
}

[Buggy Hunk]
System.arraycopy(data, offset, memory, vaddr, res);

[Patch]
System.arraycopy(data, offset, memory, paddr, res);