[Demonstration 1]

[Buggy Method]
@FXML
private void start(MouseEvent mouseEvent) {
    selectNull();
    // if the wrapper for one of the providers hasn't been initialized,
    // its active state hasn't been loaded from the config
    providerList.getItems().forEach(this::getWrapper);
    Suggester defaultSuggester = askForDefaultSuggesters();
    builder.defaultSuggester(defaultSuggester);
    this.defaultSuggester.set(defaultSuggester == null ? null : defaultSuggester.getName());
    try {
        builder.userManager(new UserManager(config, "jdbc:sqlite:users.db"));
    } catch (SQLException e) {
        logSevere("Could not connect to database: ", e);
        return;
    }
    builder.apiInitializer(RestApi::new);
    PluginLoaderController.load(stage, builder);
}

[Buggy Hunk]
logSevere("Could not connect to database: ", e);

[Patch]
logSevere(e, "Could not connect to database: ");

[Demonstration 2]

[Buggy Method]
@SuppressWarnings("unchecked")
public TDRevision putRevision(TDRevision rev, String prevRevId, boolean allowConflict, TDStatus resultStatus) {
    // prevRevId is the rev ID being replaced, or nil if an insert
    String docId = rev.getDocId();
    boolean deleted = rev.isDeleted();
    if ((rev == null) || ((prevRevId != null) && (docId == null)) || (deleted && (docId == null)) || ((docId != null) && !isValidDocumentId(docId))) {
        resultStatus.setCode(TDStatus.BAD_REQUEST);
        return null;
    }
    resultStatus.setCode(TDStatus.INTERNAL_SERVER_ERROR);
    beginTransaction();
    Cursor cursor = null;
    long docNumericID = (docId != null) ? getDocNumericID(docId) : 0;
    long parentSequence = 0;
    try {
        if (prevRevId != null) {
            // Replacing: make sure given prevRevID is current & find its sequence number:
            if (docNumericID <= 0) {
                resultStatus.setCode(TDStatus.NOT_FOUND);
                return null;
            }
            String[] args = { Long.toString(docNumericID), prevRevId };
            String additionalWhereClause = "";
            if (!allowConflict) {
                additionalWhereClause = "AND current=1";
            }
            cursor = database.rawQuery("SELECT sequence FROM revs WHERE doc_id=? AND revid=? " + additionalWhereClause + " LIMIT 1", args);
            if (cursor.moveToFirst()) {
                parentSequence = cursor.getLong(0);
            }
            if (parentSequence == 0) {
                // Not found: either a 404 or a 409, depending on whether there is any current revision
                if (!allowConflict && existsDocumentWithIDAndRev(docId, null)) {
                    resultStatus.setCode(TDStatus.CONFLICT);
                    return null;
                } else {
                    resultStatus.setCode(TDStatus.NOT_FOUND);
                    return null;
                }
            }
            // Make replaced rev non-current:
            ContentValues updateContent = new ContentValues();
            updateContent.put("current", 0);
            database.update("revs", updateContent, "sequence=" + parentSequence, null);
        } else if (docId != null) {
            if (deleted) {
                // Didn't specify a revision to delete: 404 or a 409, depending
                if (existsDocumentWithIDAndRev(docId, null)) {
                    resultStatus.setCode(TDStatus.CONFLICT);
                    return null;
                } else {
                    resultStatus.setCode(TDStatus.NOT_FOUND);
                    return null;
                }
            }
            if (docNumericID <= 0) {
                // Doc doesn't exist at all; create it:
                docNumericID = insertDocumentID(docId);
                if (docNumericID <= 0) {
                    return null;
                }
            } else {
                // Doc exists; check whether current winning revision is deleted:
                String[] args = { docId };
                cursor = database.rawQuery("SELECT sequence, deleted FROM revs WHERE doc_id=? and current=1 ORDER BY revid DESC LIMIT 1", args);
                if (cursor.moveToFirst()) {
                    boolean wasAlreadyDeleted = (cursor.getInt(1) > 0);
                    if (wasAlreadyDeleted) {
                        // Make the deleted revision no longer current:
                        ContentValues updateContent = new ContentValues();
                        updateContent.put("current", 0);
                        database.update("revs", updateContent, "sequence=" + cursor.getLong(0), null);
                    } else if (!allowConflict) {
                        // docId already exists, current not deleted, conflict
                        resultStatus.setCode(TDStatus.CONFLICT);
                        return null;
                    }
                }
            }
        } else {
            // Inserting first revision, with no docID given (POST): generate a unique docID:
            docId = TDDatabase.generateDocumentId();
            docNumericID = insertDocumentID(docId);
            if (docNumericID <= 0) {
                return null;
            }
        }
        // Bump the revID and update the JSON:
        String newRevId = generateNextRevisionID(prevRevId);
        byte[] data = null;
        if (!rev.isDeleted()) {
            data = encodeDocumentJSON(rev);
            if (data == null) {
                // bad or missing json
                resultStatus.setCode(TDStatus.BAD_REQUEST);
                return null;
            }
        }
        rev = rev.copyWithDocID(docId, newRevId);
        // Now insert the rev itself:
        long newSequence = insertRevision(rev, docNumericID, parentSequence, true, data);
        if (newSequence == 0) {
            return null;
        }
        // Store any attachments:
        if (attachments != null) {
            TDStatus status = processAttachmentsForRevision(rev, parentSequence);
            if (!status.isSuccessful()) {
                resultStatus.setCode(status.getCode());
                return null;
            }
        }
        // Success!
        if (deleted) {
            resultStatus.setCode(TDStatus.OK);
        } else {
            resultStatus.setCode(TDStatus.CREATED);
        }
    } catch (SQLException e1) {
        Log.e(TDDatabase.TAG, "Error putting revision", e1);
        return null;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        endTransaction(resultStatus.isSuccessful());
    }
    notifyChange(rev, null);
    return rev;
}

[Buggy Hunk]
String[] args = { docId };

[Patch]
String[] args = { Long.toString(docNumericID) };

[Demonstration 3]

[Buggy Method]
public boolean Done(Region region, Status status) throws FindFailed, InterruptedException {
    region.click(Common.RI_CHANG);
    Thread.sleep(3000L);
    Match tiaozhan = region.exists(baseDir + "tiaozhan.png");
    if (tiaozhan != null) {
        tiaozhan.click();
        Match qunyinghuianniu = region.exists(baseDir + "longhuqunyinghui.png", 20);
        if (qunyinghuianniu != null) {
            qunyinghuianniu.click();
            Thread.sleep(3000L);
            Match qunyinhui = region.exists(baseDir + "qunyinghui", 20);
            if (qunyinhui != null) {
                qunyinhui.click();
                if (status.canDo(Task.QUN_YING_HUI_BAO_MING)) {
                    Match canzhan = region.exists(baseDir + "canzhan.png", 20);
                    if (canzhan != null) {
                        canzhan.click();
                        Thread.sleep(6000L);
                        status.Done(Task.QUN_YING_HUI_BAO_MING);
                    } else {
                        // 找不到参战,则默认认为已经执行过群英会
                        status.Done(Task.QUN_YING_HUI_BAO_MING);
                    }
                }
                if (status.canDo(Task.QUN_YING_HUI_LING_JIANG)) {
                    Match jiangli = region.exists(baseDir + "jiangli.png", 20);
                    if (jiangli != null) {
                        jiangli.click();
                        Thread.sleep(3000L);
                        Match lingqu = region.exists(baseDir + "lingqu.png");
                        if (lingqu != null && isButtonEnable(lingqu)) {
                            lingqu.click();
                        }
                        Match lingqujiangli = region.exists(baseDir + "lingqujiangli.png");
                        log.info("lingqujiagli: {}", lingqujiangli);
                        if (lingqujiangli != null && lingqujiangli.getScore() > 0.8f) {
                            Iterator<Match> all = region.findAll(baseDir + "lingqujiangli.png");
                            Lists.newArrayList(all).forEach(x -> x.click());
                            Thread.sleep(3000L);
                        }
                    }
                    status.Done(Task.QUN_YING_HUI_LING_JIANG);
                }
                Thread.sleep(1000L);
                region.click(Common.CLOSE);
            }
            Thread.sleep(1000L);
            region.click(Common.CLOSE);
        }
    }
    return true;
}

[Buggy Hunk]
log.info("lingqujiagli: {}", lingqujiangli);

[Patch]
log.info("lingqujiagli: {}, {}", lingqujiangli, isButtonEnable(lingqujiangli));