[Demonstration 1]

[Buggy Method]
@Override
public void createLink(LinkRepresentation link, ApplicationUser user) {
    final ActiveObjects ao = ComponentGetter.getAo();
    ao.executeInTransaction(new TransactionCallback<Void>() {

        @Override
        public Void doInTransaction() {
            boolean linkAlreadyExists = false;
            for (LinkEntity linkEntity : ao.find(LinkEntity.class)) {
                if (linkEntity.getIngoingId() == link.getIngoingId() && linkEntity.getOutgoingId() == link.getOutgoingId()) {
                    linkAlreadyExists = true;
                }
            }
            if (!linkAlreadyExists) {
                link.getOutgoingId();
                DecisionComponentEntity decCompIngoing;
                DecisionComponentEntity[] decCompIngoingArray = ao.find(DecisionComponentEntity.class, Query.select().where("ID = ?", link.getIngoingId()));
                /*
                	 * ID is the primarykey for decisioncomponents, therefore find can only return 0 to 1 entities
                	 */
                if (decCompIngoingArray.length == 1) {
                    decCompIngoing = decCompIngoingArray[0];
                } else {
                    //entity with ingoingId does not exist
                    decCompIngoing = null;
                }
                DecisionComponentEntity decCompOutgoing;
                DecisionComponentEntity[] decCompOutgoingArray = ao.find(DecisionComponentEntity.class, Query.select().where("ID = ?", link.getOutgoingId()));
                if (decCompIngoingArray.length == 1) {
                    decCompOutgoing = decCompOutgoingArray[0];
                } else {
                    //entity with ingoingId does not exist
                    decCompOutgoing = null;
                }
                if (decCompIngoing != null && decCompOutgoing != null) {
                    if (decCompIngoing.getProjectKey().equals(decCompOutgoing.getProjectKey())) {
                        // entities exist and are in the same project
                        final LinkEntity linkEntity = ao.create(LinkEntity.class);
                        linkEntity.setIngoingId(link.getIngoingId());
                        linkEntity.setOutgoingId(link.getOutgoingId());
                        linkEntity.setType(link.getLinkType());
                        linkEntity.save();
                    } else {
                        // entities to be linked are not in the same project, TODO ignore request
                    }
                } else {
                    // one of the entities to be linked does not exist, TODO ignore request
                }
            }
            return null;
        }
    });
}

[Buggy Hunk]
public void createLink(LinkRepresentation link, ApplicationUser user) {

[Patch]
public void createLink(final LinkRepresentation link, ApplicationUser user) {

[Demonstration 2]

[Buggy Method]
@SuppressWarnings({ "unchecked" })
@PreAuthorize("hasRole('PRODUCTS')")
@RequestMapping(value = "/admin/categories/paging.html", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public String pageCategories(HttpServletRequest request, HttpServletResponse response) {
    String categoryName = request.getParameter("name");
    String categoryCode = request.getParameter("code");
    AjaxResponse resp = new AjaxResponse();
    try {
        Language language = (Language) request.getAttribute("LANGUAGE");
        MerchantStore store = (MerchantStore) request.getAttribute(Constants.ADMIN_STORE);
        List<Category> categories = null;
        if (!StringUtils.isBlank(categoryName)) {
            categories = categoryService.getByName(store, categoryName, language);
        } else if (!StringUtils.isBlank(categoryCode)) {
            categoryService.listByCodes(store, new ArrayList<String>(Arrays.asList(categoryCode)), language);
        } else {
            categories = categoryService.listByStore(store, language);
        }
        for (Category category : categories) {
            @SuppressWarnings("rawtypes")
            Map entry = new HashMap();
            entry.put("categoryId", category.getId());
            CategoryDescription description = category.getDescriptions().get(0);
            entry.put("name", description.getName());
            entry.put("code", category.getCode());
            entry.put("visible", category.isVisible());
            entry.put("sortOrder", category.getSortOrder());
            entry.put("parentCategory", category.getParent() != null ? category.getParent().getDescription().getName() : "");
            resp.addDataEntry(entry);
        }
        resp.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS);
    } catch (Exception e) {
        LOGGER.error("Error while paging categories", e);
        resp.setStatus(AjaxResponse.RESPONSE_STATUS_FAIURE);
    }
    String returnString = resp.toJSONString();
    return returnString;
}

[Buggy Hunk]
categoryService.listByCodes(store, new ArrayList<String>(Arrays.asList(categoryCode)), language);

[Patch]
categories = categoryService.listByCodes(store, new ArrayList<String>(Arrays.asList(categoryCode)), language);

[Demonstration 3]

[Buggy Method]
private String getEmailText(final User user, HttpServletRequest request) {
    Template template = velocityEngine.getTemplate("email.vm");
    VelocityContext context = new VelocityContext();
    context.put("email", user.getEmail());
    context.put("pass", getStarPass(user));
    context.put("link", getConfirmationLink(user, request));
    StringWriter writer = new StringWriter();
    template.merge(context, writer);
    return writer.toString();
}

[Buggy Hunk]
private String getEmailText(final User user, HttpServletRequest request) {

[Patch]
private String getEmailText(final User user, final HttpServletRequest request) {