[Demonstration 1]

[Buggy Method]
private static void _preparePomXml(File projectDir, File dir, String moduleName, String namespace) throws IOException {
    String content = FileTestUtil.read(ReplaceTranslationMojoTest.class.getClassLoader(), "com/liferay/portal/tools/soy/builder/maven/dependencies" + "/pom_xml.tmpl");
    content = content.replace("[$SOY_BUILDER_VERSION$]", _SOY_BUILDER_VERSION);
    content = content.replace("[$SOY_BUILDER_DIR$]", dir.getAbsolutePath());
    content = content.replace("[$SOY_BUILDER_MODULE_NAME$]", moduleName);
    content = content.replace("[$SOY_BUILDER_NAMESPACE$]", namespace);
    File pomXmlFile = new File(projectDir, "pom.xml");
    Files.write(pomXmlFile.toPath(), content.getBytes(StandardCharsets.UTF_8));
}

[Buggy Hunk]
ReplaceTranslationMojoTest.class.getClassLoader(),

[Patch]
WrapAlloyTemplateMojoTest.class.getClassLoader(),

[Demonstration 2]

[Buggy Method]
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response get(@CookieParam("sessionId") String sessionId, @QueryParam("filter") @DefaultValue("") String filter) {
    Response result = Response.status(401).build();
    User operator = JPAEntry.getLoginUser(sessionId);
    if (operator != null) {
        List<Scheduler> r = JPAEntry.getList(Scheduler.class, Impl.getFilters(filter));
        List<String> ids = new ArrayList<>();
        List<String> teacherIds = new ArrayList<>();
        List<String> coverIds = new ArrayList<>();
        for (Scheduler ri : r) {
            ids.add(ri.getId().toString());
            Long teacherId = ri.getTeacherId();
            if (teacherId != null) {
                teacherIds.add(teacherId.toString());
            }
            Long coverId = ri.getCoverId();
            if (coverId != null) {
                coverIds.add(coverId.toString());
            }
        }
        EntityManager em = JPAEntry.getEntityManager();
        List<User> teachers = Resources.getList(em, teacherIds, User.class);
        List<Image> covers = Resources.getList(em, coverIds, Image.class);
        Date now = new Date();
        String likeCountQuery = "SELECT l.objectId, count(l) FROM Log l WHERE l.objectType = 'scheduler' AND l.objectId IN (" + Resources.join(ids) + ") AND l.action = 'like' GROUP BY l.objectId";
        Query lq = em.createQuery(likeCountQuery);
        final List<Object[]> likeStats = lq.getResultList();
        String readCountQuery = "SELECT l.objectId, count(l) FROM Log l WHERE l.objectType = 'scheduler' AND l.objectId IN (" + Resources.join(ids) + ") AND l.action = 'read' GROUP BY l.objectId";
        Query rq = em.createQuery(readCountQuery);
        final List<Object[]> readStats = rq.getResultList();
        String likedQuery = "SELECT l.objectId, count(l) FROM Log l WHERE l.objectType = 'scheduler' AND l.objectId IN (" + Resources.join(ids) + ") AND l.action = 'read' AND l.userId = " + JPAEntry.getLoginUser(sessionId).getId().toString() + " GROUP BY l.objectId";
        Query ldq = em.createQuery(likedQuery);
        final List<Object[]> likedStats = ldq.getResultList();
        List<Comment> comments = Resources.getList(em, "objectId", ids, Comment.class);
        List<String> commentOwnerIds = comments.stream().map(c -> c.getUserId().toString()).collect(Collectors.toList());
        List<User> commentOwners = Resources.getList(em, commentOwnerIds, User.class);
        Map<String, String> orders = new HashMap<>();
        orders.put("startTime", "DESC");
        result = Impl.get(sessionId, filter, orders, Scheduler.class, scheduler -> Scheduler.convertToMap(scheduler, now, teachers, covers, likeStats, likedStats, readStats, comments, commentOwners, Users.isVIP(operator)), null);
    }
    return result;
}

[Buggy Hunk]
String likedQuery = "SELECT l.objectId, count(l) FROM Log l WHERE l.objectType = 'scheduler' AND l.objectId IN (" + Resources.join(ids) + ") AND l.action = 'read' AND l.userId = " + JPAEntry.getLoginUser(sessionId).getId().toString() + " GROUP BY l.objectId";

[Patch]
String likedQuery = "SELECT l.objectId, count(l) FROM Log l WHERE l.objectType = 'scheduler' AND l.objectId IN (" + Resources.join(ids) + ") AND l.action = 'like' AND l.userId = " + operator.getId().toString() + " GROUP BY l.objectId";

[Demonstration 3]

[Buggy Method]
@Override
public Event getSubscriptionByEventId(Integer id) {
    /*Query query = em.createQuery("SELECT sub FROM Subscription sub WHERE sub.event.id = :id");
        query.setParameter("id", id);
        Event result = (Event) query.getSingleResult();*/
    List<Event> events = em.createQuery("SELECT event FROM Event event").getResultList();
    List<Subscription> subscriptions = getAllSubscription();
    for (Subscription s : subscriptions) {
        if (s.getId() == id) {
            for (Event e : events) {
                if (e.getId() == s.getEvent().getId()) {
                    return e;
                }
            }
        }
    }
    return null;
    //return result;
}

[Buggy Hunk]
List<Event> events =  em.createQuery("SELECT event FROM Event event").getResultList();

[Patch]
List<Event> events =  eventConnector.getAllEvents();