[Demonstration 1]

[Buggy Method]
private BufferedWriter fileLog(String filePath) throws Exception {
    if (!filePath.isEmpty() && !StringHelper.equals(filePath, "-")) {
        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd_HH-mm-ss");
        String timestamp = dtf.print(new DateTime());
        File parent = new File(filePath);
        File file = new File(parent, String.format("%s.log", timestamp));
        if ((!parent.exists()) && (!parent.mkdirs())) {
            throw new IOException(String.format("Cannot create folder: %s", parent.getAbsolutePath()));
        }
        if ((!file.exists()) && (!file.createNewFile())) {
            throw new IOException(String.format("Cannot create file: %s", file.getAbsolutePath()));
        }
        FileWriter fileWriter = new FileWriter(file, true);
        return new BufferedWriter(fileWriter);
    }
    return null;
}

[Buggy Hunk]
if (!filePath.isEmpty() && !StringHelper.equals(filePath, "-"))

[Patch]
if ((filePath != null) && (!filePath.isEmpty()) && (!filePath.equals("-")))

[Demonstration 2]

[Buggy Method]
private void moveFileToArchive(File file) {
    try {
        String archiveDirPath = file.getParentFile().getAbsolutePath() + File.separator + archiveDirName;
        createDirectoryIfRequired(archiveDirPath);
        Path formerFilePath = Paths.get(file.getAbsolutePath());
        Path newDirectoryPath = Paths.get(archiveDirPath + File.separator + file.getName());
        Files.move(formerFilePath, newDirectoryPath, StandardCopyOption.REPLACE_EXISTING);
        LOG.info(StringUtils.join("File: {", file.getAbsolutePath(), "} has been moved to archivie"));
    } catch (IOException e) {
        LOG.error("Failed to move file: " + file.getAbsolutePath(), e);
    }
}

[Buggy Hunk]
LOG.error("Failed to move file: " + file.getAbsolutePath(), e);

[Patch]
LOG.error("Failed to move file: {" + file.getAbsolutePath() + "} to archive", e);

[Demonstration 3]

[Buggy Method]
public static Result service(String ownerName, String projectName, String service, boolean isAdvertise) throws IOException, UnsupportedOperationException, ServletException {
    if (!isSupportedService(service)) {
        return forbidden(String.format("Unsupported service: '%s'", service));
    }
    Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
    if (project == null) {
        return notFound();
    }
    models.User user = UserApp.currentUser();
    if (!isAllowed(project, service)) {
        if (user.isAnonymous()) {
            return BasicAuthAction.unauthorized(response());
        } else {
            // If you want the Git client showing your custom message to
            // the user, the Content-Type should be exact "text/plain"
            // without any parameter. For more details, see the code at
            // https://github.com/git/git/commit/426e70d4a11ce3b4f70636d57c6a0ab16ae08a00#diff-eea0ad565ec5903a11b6023755d491cfR154
            response().setHeader("Content-Type", "text/plain");
            return forbidden(String.format("'%s' has no permission to '%s/%s'.", user.name, ownerName, projectName));
        }
    }
    if (isAdvertise) {
        return ok(RepositoryService.gitAdvertise(project, service, response()));
    } else {
        if (request().body().isMaxSizeExceeded()) {
            return status(REQUEST_ENTITY_TOO_LARGE);
        } else {
            user.visits(project);
            return ok(RepositoryService.gitRpc(project, service, request(), response()));
        }
    }
}

[Buggy Hunk]
user.name, ownerName, projectName));

[Patch]
user.loginId, ownerName, projectName));