[Demonstration 1]

[Buggy Method]
@Test
public void testDeleteQueue() throws Exception {
    testInfo(this.getClass().getSimpleName() + " - testDeleteQueue");
    // just to be safe
    clearPermissions(account, "user");
    clearPermissions(otherAccount, "user");
    Thread.sleep(authorizationExpiryMs);
    String queueName = "queue_name_delete";
    String queueUrl = accountSQSClient.createQueue(queueName).getQueueUrl();
    // try to delete the queue as a user
    try {
        accountUserSQSClient.deleteQueue(queueName);
        assertThat(false, "Should not be able to delete queue without permission");
    } catch (AmazonServiceException e) {
        assertThat(e.getStatusCode() == 403, "Correctly fail deleting a queue without permission");
    }
    String queueArn = accountSQSClient.getQueueAttributes(queueUrl, Collections.singletonList("QueueArn")).getAttributes().get("QueueArn");
    grantPermission(account, "user", "sqs:DeleteQueue", queueArn);
    // give it some time to propegate
    Thread.sleep(authorizationExpiryMs);
    // now we should be able to delete the queue
    accountUserSQSClient.deleteQueue(queueUrl);
    // create again, and try with a wildcard resource
    accountSQSClient.createQueue(queueName).getQueueUrl();
    grantPermission(account, "user", "sqs:DeleteQueue", "*");
    // give it some time to propegate
    Thread.sleep(authorizationExpiryMs);
    // now we should be able to delete the queue
    accountUserSQSClient.deleteQueue(queueUrl);
    // Finally try to delete from a different account with a policy
    grantPermission(otherAccount, "user", "sqs:DeleteQueue", queueArn);
    accountSQSClient.createQueue(queueName).getQueueUrl();
    // give it some time to propegate
    Thread.sleep(authorizationExpiryMs);
    try {
        otherAccountUserSQSClient.deleteQueue(queueUrl);
        assertThat(false, "Should not be able to delete queue from another account");
    } catch (AmazonServiceException e) {
        assertThat(e.getStatusCode() == 403, "Correctly fail delete queue from another account");
    }
    // revoke the policies and make sure we still can't delete
    clearPermissions(account, "user");
    clearPermissions(otherAccount, "user");
    try {
        accountUserSQSClient.deleteQueue(queueUrl);
        assertThat(false, "Should not be able to delete queue without permission");
    } catch (AmazonServiceException e) {
        assertThat(e.getStatusCode() == 403, "Correctly fail delete queue without permission");
    }
    try {
        otherAccountUserSQSClient.deleteQueue(queueUrl);
        assertThat(false, "Should not be able to delete queue from another account");
    } catch (AmazonServiceException e) {
        assertThat(e.getStatusCode() == 403, "Correctly fail delete queue from another account");
    }
    // now see if the admin can do it (should be able to I think)
    sqs.deleteQueue(queueUrl);
}

[Buggy Hunk]
accountUserSQSClient.deleteQueue(queueName);

[Patch]
accountUserSQSClient.deleteQueue(queueUrl);

[Demonstration 2]

[Buggy Method]
public static Result service(String ownerName, String projectName, String service, boolean isAdvertise) throws IOException, UnsupportedOperationException, ServletException {
    if (!isSupportedService(service)) {
        return forbidden(String.format("Unsupported service: '%s'", service));
    }
    Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
    if (project == null) {
        return notFound();
    }
    models.User user = UserApp.currentUser();
    if (!isAllowed(project, service)) {
        if (user.isAnonymous()) {
            return BasicAuthAction.unauthorized(response());
        } else {
            // If you want the Git client showing your custom message to
            // the user, the Content-Type should be exact "text/plain"
            // without any parameter. For more details, see the code at
            // https://github.com/git/git/commit/426e70d4a11ce3b4f70636d57c6a0ab16ae08a00#diff-eea0ad565ec5903a11b6023755d491cfR154
            response().setHeader("Content-Type", "text/plain");
            return forbidden(String.format("'%s' has no permission to '%s/%s'.", user.name, ownerName, projectName));
        }
    }
    if (isAdvertise) {
        return ok(RepositoryService.gitAdvertise(project, service, response()));
    } else {
        if (request().body().isMaxSizeExceeded()) {
            return status(REQUEST_ENTITY_TOO_LARGE);
        } else {
            user.visits(project);
            return ok(RepositoryService.gitRpc(project, service, request(), response()));
        }
    }
}

[Buggy Hunk]
user.name, ownerName, projectName));

[Patch]
user.loginId, ownerName, projectName));

[Demonstration 3]

[Buggy Method]
private void processJobRun(Batch batch, JobID jobID) throws Exception {
    String BATCH_ID = jobID.getBatchID();
    String JOB_ID = jobID.getJobID();
    String historyDir = FileNames.getResultDirectoryMonitoringDirectory(jobID);
    History history = History.importXML(new File(historyDir));
    MethodHistories methodHistories = history.getMethodHistories();
    methodHistories.sortMethodInstancesByName();
    String TITLE1 = "Průběh jednotlivých metod";
    String TITLE2 = jobID.getBatchID() + "-" + JOB_ID + "-R" + jobID.getRunNumber();
    String YLABEL = "jádra systému a jejich vytížení instancemi metod";
    String OUTPUT_FILE = BATCH_ID + getClass().getSimpleName().replace("PostProc", "") + JOB_ID + "" + jobID.getRunNumber();
    String OUTPUT_PATH = FileNames.getResultDirectoryForMatlab(batch.getBatchID());
    int numOfIter = (int) history.getMethodHistories().exportNumberOfLastIteration();
    String matlabCode = "h = figure" + NL + "hold on" + NL + "title({'" + TITLE1 + "' ; '" + TITLE2 + "'});" + NL + "ylabel('y: " + YLABEL + "', 'FontSize', 10);" + NL + NL;
    List<String> labelsList = new ArrayList<>();
    List<String> hsList = new ArrayList<>();
    for (int i = 0; i < methodHistories.getMethods().size(); i++) {
        MethodHistory methodHistoryI = methodHistories.getMethods().get(i);
        MethodInstanceDescription methodInstanceI = methodHistoryI.getMethodInstanceDescription();
        List<MethodStatisticResultWrapper> statisticsI = methodHistoryI.getStatistics();
        List<Double> valuesI = getMethodValues(methodInstanceI, statisticsI, numOfIter, i + 1);
        String valuesStringI = MatlabTool.convertDoublesToMatlamArray(valuesI);
        matlabCode += "h" + i + " = " + "plot([1:" + (numOfIter + 1) + "], " + valuesStringI + ", '-o');" + NL;
        labelsList.add(methodInstanceI.exportInstanceName());
        hsList.add("h" + i);
    }
    Collections.reverse(labelsList);
    String descriptions = MatlabTool.createLabels(labelsList);
    Collections.reverse(hsList);
    String hs = MatlabTool.convertStringsToMatlamArray(hsList);
    matlabCode += "labels = " + descriptions + ";" + NL + "legend(" + hs + ", labels,'Location','southoutside','Orientation','vertical');" + NL + "x1=xlim;" + NL + "y1=ylim;" + NL + "xlim([x1(1)-1, x1(2)+1]);" + NL + "ylim([y1(1)-1, y1(2)+1]);" + NL + "hold off" + NL + "h.PaperPositionMode = 'auto'" + NL + "fig_pos = h.PaperPosition;" + NL + "h.PaperSize = [fig_pos(3) fig_pos(4)];" + NL + "saveas(h, '" + OUTPUT_FILE + "','bmp');" + NL + "print(h, '-fillpage', '" + OUTPUT_FILE + "','-dpdf');" + NL + "exit;";
    System.out.println(matlabCode);
    saveAndProcessMatlab(matlabCode, OUTPUT_PATH, OUTPUT_FILE);
}

[Buggy Hunk]
int numOfIter = (int) history.getMethodHistories().exportNumberOfLastIteration();

[Patch]
int numOfIter = history.getRePlans().size();