[Demonstration 1]

[Buggy Method]
public File addFile(String filepath, String data) {
    if (this.ft.get(filepath) != null) {
        return null;
    }
    String[] paths = filepath.substring(1).split("/");
    String filename = paths[paths.length - 1];
    String currentPath = "";
    File currentFile = this.ft.get("/");
    for (int i = 0; i < paths.length - 1; i++) {
        currentPath = currentPath + "/" + paths[i];
        if ((currentFile = this.ft.get(currentPath)) == null) {
            return null;
        }
    }
    File f = new File(filename, data);
    this.ft.put(filepath, f);
    currentFile.addChild(f);
    f.setPredecessor(currentFile);
    return f;
}

[Buggy Hunk]
File f = new File(filename, data);

[Patch]
File f = new File(filepath, data);

[Demonstration 2]

[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));

[Demonstration 3]

[Buggy Method]
private void configureIdeaModule(Project project, final SourceSet mainSourceSet, final SourceSet testSourceSet) {
    project.afterEvaluate(new Action<Project>() {

        @Override
        public void execute(Project project) {
            final IdeaModule ideaModule = project.getExtensions().getByType(IdeaModel.class).getModule();
            Set<File> excl = new LinkedHashSet<>();
            for (SourceSet sourceSet : new SourceSet[] { mainSourceSet, testSourceSet }) {
                File generatedSourcesDir = new DslObject(sourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
                for (File f = generatedSourcesDir; f != null && f != project.getProjectDir(); f = f.getParentFile()) {
                    excl.add(f);
                }
            }
            // For some reason, modifying the existing collections doesn't work.
            // We need to copy the values and then assign it back.
            Set<File> excludeDirs = new LinkedHashSet<>(ideaModule.getExcludeDirs());
            if (excl.contains(project.getBuildDir()) && ideaModule.getExcludeDirs().contains(project.getBuildDir())) {
                ideaModule.getExcludeDirs().remove(project.getBuildDir());
                // Race condition: many of these will actually be created afterwards…
                File[] subdirs = project.getBuildDir().listFiles(new FileFilter() {

                    @Override
                    public boolean accept(File pathname) {
                        return pathname.isDirectory();
                    }
                });
                if (subdirs != null) {
                    excludeDirs.addAll(Arrays.asList(subdirs));
                }
            }
            excludeDirs.removeAll(excl);
            ideaModule.setExcludeDirs(excludeDirs);
            File mainGeneratedSourcesDir = new DslObject(mainSourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
            File testGeneratedSourcesDir = new DslObject(testSourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
            // For some reason, modifying the existing collections doesn't work.
            // We need to copy the values and then assign it back.
            ideaModule.setSourceDirs(addToSet(ideaModule.getSourceDirs(), mainGeneratedSourcesDir));
            ideaModule.setTestSourceDirs(addToSet(ideaModule.getTestSourceDirs(), testGeneratedSourcesDir));
            ideaModule.setGeneratedSourceDirs(addToSet(ideaModule.getGeneratedSourceDirs(), mainGeneratedSourcesDir, testGeneratedSourcesDir));
            final AptPlugin.AptSourceSetConvention mainSourceSetConvention = new DslObject(mainSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class);
            final AptPlugin.AptSourceSetConvention testSourceSetConvention = new DslObject(testSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class);
            if (GradleVersion.current().compareTo(GradleVersion.version("3.4")) >= 0) {
                // Gradle 3.4 changed IDEA mappings
                // See https://docs.gradle.org/3.4/release-notes.html#idea-mapping-has-been-simplified
                ideaModule.getScopes().get("PROVIDED").get("plus").add(project.getConfigurations().getByName(mainSourceSetConvention.getAptConfigurationName()));
                ideaModule.getScopes().get("TEST").get("plus").add(project.getConfigurations().getByName(testSourceSetConvention.getAptConfigurationName()));
            } else {
                // NOTE: ideally we'd use PROVIDED for both, but then every transitive dependency in
                // compile or testCompile configurations that would also be in compileOnly and
                // testCompileOnly would end up in PROVIDED.
                ideaModule.getScopes().get("COMPILE").get("plus").addAll(Arrays.asList(project.getConfigurations().getByName(mainSourceSetConvention.getCompileOnlyConfigurationName()), project.getConfigurations().getByName(mainSourceSetConvention.getAptConfigurationName())));
                ideaModule.getScopes().get("TEST").get("plus").addAll(Arrays.asList(project.getConfigurations().getByName(testSourceSetConvention.getCompileOnlyConfigurationName()), project.getConfigurations().getByName(testSourceSetConvention.getAptConfigurationName())));
            }
        }

        private Set<File> addToSet(Set<File> sourceDirs, File... dirs) {
            Set<File> newSet = new LinkedHashSet<>(sourceDirs);
            newSet.addAll(Arrays.asList(dirs));
            return newSet;
        }
    });
}

[Buggy Hunk]
f != null && f != project.getProjectDir();

[Patch]
f != null && !f.equals(project.getProjectDir());