[Demonstration 1]

[Buggy Method]
public NearestVersion locate(final Git git) throws GitAPIException, IOException {
    // Look for in progress release branch
    List<Ref> branches = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
    final Ref releaseInProgress = Iterables.find(branches, new Predicate<Ref>() {

        @Override
        public boolean apply(Ref input) {
            return input.getName().startsWith("refs/heads/release/");
        }
    }, null);
    // If a release is in progress
    NearestVersion nearestVersion = null;
    if (releaseInProgress != null) {
        Version releaseInProgressVersion = null;
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Found in progress release branch " + releaseInProgress.getName());
        }
        try {
            releaseInProgressVersion = Version.valueOf(releaseInProgress.getName().substring("refs/heads/release/".length()));
        } catch (ParseException e) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Ignoring release branch (name is not semver)" + releaseInProgress.getName());
            }
        }
        if (releaseInProgressVersion != null) {
            final ObjectId releaseId = releaseInProgress.getObjectId();
            int distance = distanceFromReleaseMergeBase(git, releaseId);
            // If we're at least 1 commit away from release branch merge base
            // then consider the release branch merge base as the nearest version
            // otherwise fallback to locate nearest release tag
            if (distance > 0) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Extracted version {} from release branch name {} at {} [MERGE_BASE+{}]", releaseInProgressVersion.getNormalVersion(), releaseId, distance);
                }
                nearestVersion = new NearestVersion(releaseInProgressVersion, distance);
            } else {
                LOGGER.debug("On or behind release branch merge base so doing as if there was no release in progress");
            }
        }
    }
    // If nearest version is not a release branch merge base then locate nearest release tag
    if (nearestVersion == null) {
        nearestVersion = localTag(git);
        final ObjectId releaseId = nearestVersion.getObjectId();
        if (releaseId != null) {
            final int distance = distanceFromReleaseMergeBase(git, releaseId);
            nearestVersion = new NearestVersion(nearestVersion.getAny(), distance);
        }
    }
    return nearestVersion;
}

[Buggy Hunk]
LOGGER.debug("Extracted version {} from release branch name {} at {} [MERGE_BASE+{}]", releaseInProgressVersion.getNormalVersion(), releaseId, distance);

[Patch]
LOGGER.debug("Extracted version {} from release branch name {} at {} [MERGE_BASE+{}]", releaseInProgressVersion.getNormalVersion(), releaseInProgress.getName(), releaseId.abbreviate(7).name(), distance);

[Demonstration 2]

[Buggy Method]
private boolean getTicket(String key, int interval, int retry) {
    if (retry <= 0) {
        return false;
    }
    try {
        GlobalJobDo globalJobDo = globalJobDao.findByPK(key, GlobalJobEntity.READSET_FULL);
        if (globalJobDo == null) {
            globalJobDo = new GlobalJobDo().setJobKey(key).setStartTime(new Date()).setStatus("DOING").setDataChangeLastTime(new Date()).setFinishTime(new Date()).setOwner(S.getIp());
            globalJobDao.updateByPK(globalJobDo, GlobalJobEntity.UPDATESET_FULL);
            return true;
        } else {
            if (!globalJobDo.getStatus().equals("DOING")) {
                long last = globalJobDo.getFinishTime() == null ? 0 : globalJobDo.getFinishTime().getTime();
                long time = System.currentTimeMillis() - last;
                if (time >= interval) {
                    globalJobDo.setStartTime(new Date()).setStatus("DOING").setDataChangeLastTime(new Date()).setOwner(S.getIp());
                    globalJobDao.updateByPK(globalJobDo, GlobalJobEntity.UPDATESET_FULL);
                    return true;
                } else {
                    return false;
                }
            } else {
                long last = globalJobDo.getFinishTime() == null ? 0 : globalJobDo.getFinishTime().getTime();
                long time = System.currentTimeMillis() - last;
                if (time >= 10 * interval) {
                    globalJobDo.setStartTime(new Date()).setStatus("DOING").setDataChangeLastTime(new Date()).setOwner(S.getIp());
                    globalJobDao.updateByPK(globalJobDo, GlobalJobEntity.UPDATESET_FULL);
                    return true;
                } else {
                    return false;
                }
            }
        }
    } catch (Exception e) {
        retry--;
        logger.info("[HealthCheckFetchJob]getTicket retry.retry:" + retry, e);
        return getTicket(key, interval, retry);
    }
}

[Buggy Hunk]
globalJobDao.updateByPK(globalJobDo, GlobalJobEntity.UPDATESET_FULL);

[Patch]
globalJobDao.insert(globalJobDo);

[Demonstration 3]

[Buggy Method]
private String encodeJson(Object apply) {
    try {
        return mapper.writeValueAsString(apply);
    } catch (JsonProcessingException e) {
        throw new RuntimeException("couldn't serialize object");
    }
}

[Buggy Hunk]
throw new RuntimeException("couldn't serialize object");

[Patch]
throw new RuntimeException("couldn't serialize object", e);