[Demonstration 1]

[Buggy Method]
@POST
@Path("/policy/update")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, "*/*" })
public Response update(@Context HttpHeaders hh, @Context HttpServletRequest request, String requestBody, @QueryParam("force") Boolean force) throws Exception {
    ExtendedView.ExtendedTrafficPolicy extendedView = ObjectJsonParser.parse(requestBody, ExtendedView.ExtendedTrafficPolicy.class);
    TrafficPolicy p = ObjectJsonParser.parse(requestBody, TrafficPolicy.class);
    if (p == null) {
        throw new ValidationException("Invalid post entity. Fail to parse json to traffic-policy.");
    }
    if (p.getName() == null) {
        throw new ValidationException("Field `name` is not allowed empty.");
    }
    trim(p);
    Long checkId = trafficPolicyQuery.queryByName(p.getName());
    if (checkId > 0L) {
        throw new ValidationException("Traffic policy name has been taken by " + checkId + ".");
    }
    p = trafficPolicyRepository.update(p, force != null && force);
    if (extendedView.getProperties() != null) {
        setProperties(p.getId(), extendedView.getProperties());
    }
    if (extendedView.getTags() != null) {
        addTag(p.getId(), extendedView.getTags());
    }
    try {
        if (trafficPolicyQuery.queryByIdAndMode(p.getId(), SelectionMode.ONLINE_EXCLUSIVE).length == 1) {
            propertyBox.set("status", "toBeActivated", "policy", p.getId());
        }
    } catch (Exception ex) {
    }
    return responseHandler.handle(p, hh.getMediaType());
}

[Buggy Hunk]
if (checkId > 0L) {

[Patch]
if (checkId > 0L && !checkId.equals(p.getId())) {

[Demonstration 2]

[Buggy Method]
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    boolean notValid = false;
    Period p = periods.get(rowIndex);
    LocalDate newDate = null;
    if (columnIndex == 0 || columnIndex == 1) {
        newDate = (LocalDate) aValue;
        if (columnIndex == 0) {
            if (p.getStartDate().equals(newDate))
                return;
            notValid = p.getEndDate().isBefore(newDate);
        } else {
            if (p.getEndDate().equals(newDate))
                return;
            notValid = p.getStartDate().isAfter(newDate);
        }
    }
    if (notValid) {
        JOptionPane.showMessageDialog(mc.getMainWindow(), "The date is not valid. " + "Please make sure that the start date of the period is before the end date.");
    } else {
        if (columnIndex == 0) {
            p.setStartDate(newDate);
            if (rowIndex == 0) {
                if (periods.size() >= 2) {
                    int newRecDays = Days.daysBetween(periods.get(rowIndex + 1).getStartDate(), newDate).getDays();
                    p.setRecurrenceDays(newRecDays);
                    p.setEndDate(p.getStartDate().plusDays(p.getRecurrenceDays()));
                }
            } else {
                Period pNext = periods.get(rowIndex - 1);
                if (pNext.isFuture()) {
                    pNext.setStartDate(p.getStartDate().plusDays(p.getRecurrenceDays()));
                    pNext.setEndDate(p.getEndDate().plusDays(p.getRecurrenceDays()));
                    pNext.setRecurrenceDays(p.getRecurrenceDays());
                }
                fireTableRowsUpdated(rowIndex - 1, rowIndex);
            }
        } else if (columnIndex == 1) {
            p.setEndDate(newDate);
            //Change the duration for all future periods
            int durationDays = p.getDurationDays();
            Period thePeriod;
            for (int index = rowIndex - 1; rowIndex > 0; rowIndex--) {
                thePeriod = periods.get(index);
                if (thePeriod.isFuture()) {
                    thePeriod.setEndDate(thePeriod.getStartDate().plusDays(durationDays));
                }
            }
            fireTableRowsUpdated(0, rowIndex);
        }
        fireTableCellUpdated(rowIndex, columnIndex);
    }
}

[Buggy Hunk]
p.setEndDate(p.getStartDate().plusDays(p.getRecurrenceDays()));

[Patch]
p.setEndDate(periods.get(rowIndex + 1).getEndDate().plusDays(p.getRecurrenceDays()));

[Demonstration 3]

[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));