[Demonstration 1]

[Buggy Method]
@Override
protected boolean documentComplies(DocumentEventContext ctx) {
    DocumentModel doc = ctx.getSourceDocument();
    String title = (String) doc.getPropertyValue("dc:title");
    // checking if document has a title
    if (StringUtils.isEmpty(title)) {
        // Ignore document
        return true;
    }
    // checking if document is created under a specific folderish document
    if (!StringUtils.startsWith((String) ctx.getProperty(CoreEventConstants.DESTINATION_PATH), "/default-domain/workspaces/ws1")) {
        // Ignore document
        return true;
    }
    // rejecting documents with same title only of type 'File'
    if (!docTypesToCheck.contains(doc.getType())) {
        // Ignore document
        return true;
    }
    setMessage("document with same title already exists in " + (String) ctx.getProperty(CoreEventConstants.DESTINATION_PATH));
    // retrieving parent folderish document
    DocumentRef parentRef = (DocumentRef) ctx.getProperty(CoreEventConstants.DESTINATION_REF);
    DocumentModel parentDoc = ctx.getCoreSession().getDocument(parentRef);
    // searching for documents with same title in the parent folderish document
    StringBuilder sb = new StringBuilder("SELECT " + NXQL.ECM_UUID + " FROM Document WHERE ");
    sb.append("dc:title").append(Operator.EQ.toString()).append(NXQL.escapeString(title)).append(" " + Operator.AND.toString() + " ").append(NXQL.ECM_PARENTID).append(Operator.EQ.toString()).append(NXQL.escapeString(parentDoc.getId())).append(" " + Operator.AND.toString() + " ").append(NXQL.ECM_ISCHECKEDIN).append(Operator.EQ.toString() + "0");
    LOG.debug("NXQL query: " + sb.toString());
    IterableQueryResult result = ctx.getCoreSession().queryAndFetch(sb.toString(), NXQL.NXQL);
    LOG.debug("result nbr: " + result.size());
    return (result.size() == 0);
}

[Buggy Hunk]
setMessage("document with same title already exists in " + (String) ctx.getProperty(CoreEventConstants.DESTINATION_PATH));

[Patch]
setMessage(ERROR_MESSAGE_PREFIX + "document with same title already exists in " + (String) ctx.getProperty(CoreEventConstants.DESTINATION_PATH));

[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]
@POST
@Path("upload")
@Consumes("multipart/form-data")
@Produces(MediaType.APPLICATION_JSON)
public Response createInvoiceFromXml(final MultipartFormDataInput input) {
    auth.requireManage();
    Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    List<InputPart> inputParts = uploadForm.get("file");
    for (InputPart inputPart : inputParts) {
        try {
            InputStream inputStream = inputPart.getBody(InputStream.class, null);
            byte[] bytes = IOUtils.toByteArray(inputStream);
            InvoiceType invoiceType = session.getProvider(UBLInvoiceProvider.class).reader().read(bytes);
            if (invoiceType == null) {
                throw new ModelException("Invalid invoice Xml");
            }
            InvoiceManager invoiceManager = new InvoiceManager(session);
            // Double-check duplicated documentId
            if (invoiceType.getIDValue() != null && invoiceManager.getInvoiceByDocumentId(organization, invoiceType.getIDValue()) != null) {
                throw new ModelDuplicateException("Invoice exists with same documentId[" + invoiceType.getIDValue() + "]");
            }
            InvoiceModel invoice = invoiceManager.addInvoice(organization, invoiceType, Collections.emptyMap());
            adminEvent.operation(OperationType.CREATE).resourcePath(uriInfo, invoice.getId()).representation(invoiceType).success();
        } catch (IOException e) {
            if (session.getTransactionManager().isActive()) {
                session.getTransactionManager().setRollbackOnly();
            }
            logger.error("Error reading input data", e);
            return ErrorResponse.error("Error Reading data", Response.Status.BAD_REQUEST);
        } catch (ModelDuplicateException e) {
            if (session.getTransactionManager().isActive()) {
                session.getTransactionManager().setRollbackOnly();
            }
            return ErrorResponse.exists("Invoice exists with same id or documentId");
        } catch (ModelException e) {
            if (session.getTransactionManager().isActive()) {
                session.getTransactionManager().setRollbackOnly();
            }
            return ErrorResponse.exists("Could not create invoice");
        }
    }
    return Response.ok().build();
}

[Buggy Hunk]
adminEvent.operation(OperationType.CREATE).resourcePath(uriInfo, invoice.getId()).representation(invoiceType).success();

[Patch]
adminEvent.operation(OperationType.CREATE).resource(ResourceType.INVOICE).resourcePath(uriInfo, invoice.getId()).representation(invoiceType).success();