[Demonstration 1]

[Buggy Method]
public List<NetworkSet> getNetworkSetsByUserId(UUID userId, UUID signedInUserId, int offset, int limit) throws SQLException, JsonParseException, JsonMappingException, IOException {
    List<NetworkSet> result = new ArrayList<>();
    String sqlStr = "select creation_time, modification_time, \"UUID\", name, description, other_attributes,showcased from network_set  where owner_id=? and is_deleted=false";
    if (offset >= 0 && limit > 0) {
        sqlStr += " limit " + offset + " offset " + limit;
    }
    try (PreparedStatement p = db.prepareStatement(sqlStr)) {
        p.setObject(1, userId);
        try (ResultSet rs = p.executeQuery()) {
            while (rs.next()) {
                NetworkSet entry = new NetworkSet();
                entry.setCreationTime(rs.getTimestamp(1));
                entry.setModificationTime(rs.getTimestamp(2));
                entry.setExternalId((UUID) rs.getObject(3));
                entry.setOwnerId(userId);
                entry.setName(rs.getString(4));
                entry.setDescription(rs.getString(5));
                String propStr = rs.getString(6);
                if (propStr != null) {
                    ObjectMapper mapper = new ObjectMapper();
                    TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
                    };
                    HashMap<String, Object> o = mapper.readValue(propStr, typeRef);
                    entry.setProperties(o);
                }
                entry.setShowcased(rs.getBoolean(7));
                entry.setOwnerId(userId);
                result.add(entry);
            }
        }
    }
    sqlStr = "select network_id from network_set_member nm, network n where nm.set_id =? and nm.network_id = n.\"UUID\" and " + NetworkDAO.createIsReadableConditionStr(signedInUserId);
    for (NetworkSet entry : result) {
        try (PreparedStatement p = db.prepareStatement(sqlStr)) {
            p.setObject(1, entry.getExternalId());
            try (ResultSet rs = p.executeQuery()) {
                List<UUID> networkIds = entry.getNetworks();
                while (rs.next()) {
                    networkIds.add((UUID) rs.getObject(1));
                }
            }
        }
    }
    return result;
}

[Buggy Hunk]
sqlStr += " limit " +offset + " offset " + limit;

[Patch]
sqlStr += " limit " +limit + " offset " + offset;

[Demonstration 2]

[Buggy Method]
public static void setProperties() throws MessagingException {
    Properties props = new Properties();
    //props.put("mail.store.protocol", "imaps");
    props.put(protocolForRetrievingData, messageAccessProtocol);
    Session session = Session.getDefaultInstance(props, null);
    //Store store = session.getStore("imaps");
    store = session.getStore(messageAccessProtocol);
    //store.connect("imap.googlemail.com","apostollmatt9@gmail.com", "Slayer41");
    store.connect(host, email, password);
}

[Buggy Hunk]
public static void setProperties() throws MessagingException {

[Patch]
public void setProperties() throws MessagingException {

[Demonstration 3]

[Buggy Method]
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    logger.info("ping checks requested");
    Checks checks = new Checks(req);
    List<Check> all = checks.all();
    logger.info(all.size() + " checks found");
    Pinger pinger = new Pinger();
    for (Check check : all) {
        Result result = pinger.ping(check.getUrl());
        logger.info("ping " + check.getUrl() + " " + result.status());
        if (checks.update(check, result)) {
            logger.info("status changed, sending notification");
            notify(req.getUserPrincipal().getName(), check, result);
        }
    }
    // if (req.getUserPrincipal() != null) {
    // String name = req.getUserPrincipal().getName();
    // User fetched = ofy().load().type(User.class).filter("email", name)
    // .first().now();
    // User user = new User(name);
    // ofy().save().entity(user).now(); // async without the now()
}

[Buggy Hunk]
notify(req.getUserPrincipal().getName(), check, result);

[Patch]
notify(check, result);