[Demonstration 1]

[Buggy Method]
@Override
public MaterializedViewExecution lockAndUpdateView(String project, MaterializedView materializedView) {
    CompletableFuture<Instant> f = new CompletableFuture<>();
    String tableName = queryExecutor.formatTableReference(project, QualifiedName.of("materialized", materializedView.tableName), Optional.empty(), ImmutableMap.of(), "collection");
    Query statement;
    synchronized (sqlParser) {
        statement = (Query) sqlParser.createStatement(materializedView.query);
    }
    Map<String, String> sessionProperties = new HashMap<>();
    if (!materializedView.incremental) {
        if (!materializedView.needsUpdate(Clock.systemUTC()) || !database.updateMaterializedView(project, materializedView, f)) {
            return new MaterializedViewExecution(null, tableName);
        }
        String collection = ValidationUtil.checkCollection(MATERIALIZED_VIEW_PREFIX + materializedView.tableName);
        QueryExecution execution = queryExecutor.executeRawStatement(format("REFRESH MATERIALIZED VIEW %s.%s ", project, collection));
        DelegateQueryExecution delegateQueryExecution = new DelegateQueryExecution(execution, result -> {
            f.complete(!result.isFailed() ? Instant.now() : null);
            return result;
        });
        return new MaterializedViewExecution(delegateQueryExecution, collection);
    } else {
        List<String> referencedCollections = new ArrayList<>();
        formatSql(statement, name -> {
            if (name.getPrefix().map(prefix -> prefix.equals("collection")).orElse(true)) {
                referencedCollections.add(name.getSuffix());
            }
            return null;
        }, '"');
        String materializedTableReference = tableName;
        Instant lastUpdated = materializedView.lastUpdate;
        Instant now = Instant.now();
        boolean needsUpdate = lastUpdated == null || Duration.between(now, lastUpdated).compareTo(materializedView.updateInterval) > 0;
        QueryExecution queryExecution;
        if (needsUpdate && database.updateMaterializedView(project, materializedView, f)) {
            String query = formatSql(statement, name -> {
                String predicate = lastUpdated != null ? String.format("between to_timestamp(%d) and to_timestamp(%d)", lastUpdated.getEpochSecond(), now.getEpochSecond()) : String.format(" < to_timestamp(%d)", now.getEpochSecond());
                return format("(SELECT * FROM %s WHERE _time %s)", queryExecutor.formatTableReference(project, name, Optional.empty(), ImmutableMap.of(), "collection"), predicate);
            }, '"');
            queryExecution = queryExecutor.executeRawStatement(format("INSERT INTO %s %s", materializedTableReference, query), sessionProperties);
            queryExecution.getResult().thenAccept(result -> f.complete(!result.isFailed() ? now : null));
        } else {
            queryExecution = QueryExecution.completedQueryExecution("", QueryResult.empty());
            f.complete(lastUpdated);
        }
        String reference;
        if (!needsUpdate || true) {
            reference = materializedTableReference;
        } else {
            String query = formatSql(statement, name -> format("(SELECT * FROM %s %s", queryExecutor.formatTableReference(project, name, Optional.empty(), ImmutableMap.of(), "collection"), lastUpdated == null ? "" : String.format("WHERE _time > to_timestamp(%d)", lastUpdated)), '"');
            reference = format("(SELECT * from %s UNION ALL %s)", materializedTableReference, query);
        }
        return new MaterializedViewExecution(queryExecution, reference);
    }
}

[Buggy Hunk]
String collection = ValidationUtil.checkCollection( MATERIALIZED_VIEW_PREFIX + materializedView.tableName);

[Patch]
String collection = checkCollection( MATERIALIZED_VIEW_PREFIX + materializedView.tableName);

[Demonstration 2]

[Buggy Method]
public static JsonObject createDeleteDocument(JsonObject deleteQuery, String collection, boolean justOne) {
    JsonObject delete = new JsonObject();
    delete.putBoolean("just_one", true);
    delete.putString("collection", collection);
    delete.putObject("query", deleteQuery);
    return delete;
}

[Buggy Hunk]
delete.putBoolean("just_one", true);

[Patch]
delete.putBoolean("just_one", justOne);

[Demonstration 3]

[Buggy Method]
@Before
public void setUp() {
    historyPage = new AccountHistoryPage(template, tableBuilder, accountPager);
}

[Buggy Hunk]
historyPage = new AccountHistoryPage(template, tableBuilder, accountPager);

[Patch]
historyPage = new AccountHistoryPage(template, tableBuilder, accountPager, sessionProvider);