[Demonstration 1]

[Buggy Method]
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void run() {
    synchronized (managedStateImpl.commitLock) {
        //freeing of state needs to be stopped during commit as commit results in transferring data to a state which
        // can be freed up as well.
        long bytesSum = 0;
        for (Bucket bucket : managedStateImpl.buckets) {
            if (bucket != null) {
                bytesSum += bucket.getSizeInBytes();
            }
        }
        if (bytesSum > managedStateImpl.getMaxMemorySize()) {
            Duration duration = managedStateImpl.getDurationPreventingFreeingSpace();
            long durationMillis = 0;
            if (duration != null) {
                durationMillis = duration.getMillis();
            }
            BucketIdTimeWrapper idTimeWrapper;
            while (bytesSum > managedStateImpl.getMaxMemorySize() && bucketHeap.size() > 0 && null != (idTimeWrapper = bucketHeap.first())) {
                //trigger buckets to free space
                if (System.currentTimeMillis() - idTimeWrapper.getLastAccessedTime() < durationMillis) {
                    //if the least recently used bucket cannot free up space because it was accessed within the
                    //specified duration then subsequent buckets cannot free space as well because this heap is ordered by time.
                    break;
                }
                long bucketId = idTimeWrapper.bucketId;
                Bucket bucket = managedStateImpl.getBucket(bucketId);
                if (bucket != null) {
                    synchronized (bucket) {
                        long sizeFreed;
                        try {
                            sizeFreed = bucket.freeMemory(managedStateImpl.checkpointManager.getLastTransferredWindow());
                            LOG.debug("bucket freed {} {}", bucketId, sizeFreed);
                        } catch (IOException e) {
                            managedStateImpl.throwable.set(e);
                            throw new RuntimeException("freeing " + bucketId, e);
                        }
                        bytesSum -= sizeFreed;
                    }
                    bucketHeap.remove(idTimeWrapper);
                    bucketAccessTimes.remove(bucketId);
                }
            }
        }
    }
}

[Buggy Hunk]
sizeFreed = bucket.freeMemory(managedStateImpl.checkpointManager.getLastTransferredWindow());

[Patch]
sizeFreed = bucket.freeMemory(managedStateImpl.getCheckpointManager().getLastTransferredWindow());

[Demonstration 2]

[Buggy Method]
@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
    // Broadcasts to all a message
    /*Bukkit.broadcastMessage(event.getPlayer().getName() + " dropped "
            + event.getItemDrop());*/
    //Check if dropped item matches specific item
    if (daily.equals(daily2 + " - " + randFood) && (event.getItemDrop().getItemStack().getType().equals(randFood))) {
        // Test message to verify that item type is being tracked correctly.
        /*Bukkit.broadcastMessage(event.getPlayer().getName() + " dropped tested 1 "
                    + randFood);*/
        // increment item drop counter
        dropCount++;
    }
    // Check if dropCount matches goals (test amount)
    if (dropCount == 5) {
        Bukkit.broadcastMessage(event.getPlayer().getName() + " dropped 5 " + Material.BRICK.name());
        Bukkit.broadcastMessage(event.getPlayer().getName() + " dropped 5 " + randFood);
        // reset item drop counter
        dropCount = 0;
        dailyReward = true;
    }
}

[Buggy Hunk]
if (daily.equals(daily2 + " - " + randFood) && (event.getItemDrop().getItemStack().getType().equals(randFood))){

[Patch]
if (challengeTitle.equals(daily2 + " - " + randFood) && (event.getItemDrop().getItemStack().getType().equals(randFood))){

[Demonstration 3]

[Buggy Method]
private int insertPowerGrid(String uuid, String name, List<String> problems) {
    List<Powergrid> grids = getAvailablePowergrids();
    int maxPg = 0;
    for (Powergrid g : grids) {
        if (g.getPowergridId() > maxPg) {
            maxPg = g.getPowergridId();
        }
    }
    String insert = "INSERT INTO powergrid(PowergridId, Name,CoordinateSystem,Mrid) VALUES(?,?,?,?);";
    int pgId = maxPg + 1;
    try (Connection conn = getConnection()) {
        try (PreparedStatement stmt = conn.prepareStatement(insert, Statement.RETURN_GENERATED_KEYS)) {
            stmt.setInt(1, pgId);
            stmt.setString(2, name);
            stmt.setString(3, "");
            stmt.setString(4, uuid);
            stmt.execute();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return pgId;
}

[Buggy Hunk]
try(Connection conn = getConnection()){

[Patch]
try(Connection conn = pooledDatasource.getConnection()){