[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]
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]
public MachineState getStateFromBase() {
    Set<GdlSentence> contents = new HashSet<GdlSentence>();
    for (Proposition p : propNet.getBasePropositions().values()) {
        p.setValue(getPropMark(p.getSingleInput()));
        if (p.getValue()) {
            contents.add(p.getName());
        }
    }
    return new MachineState(contents);
}

[Buggy Hunk]
p.setValue(getPropMark(p.getSingleInput()));

[Patch]
p.setValue(p.getSingleInput().getValue());