[Demonstration 1]

[Buggy Method]
protected final Module loadModuleLocal(String name) throws ModuleLoadException {
    FutureModule futureModule = moduleMap.get(name);
    if (futureModule != null) {
        return futureModule.getModule();
    }
    FutureModule newFuture = new FutureModule(name);
    futureModule = moduleMap.putIfAbsent(name, newFuture);
    if (futureModule != null) {
        return futureModule.getModule();
    }
    boolean ok = false;
    try {
        final ModuleLogger log = Module.log;
        log.trace("Locally loading module %s from %s", name, this);
        final long startTime = Metrics.getCurrentCPUTime();
        final ModuleSpec moduleSpec = findModule(name);
        loadTime.addAndGet(Metrics.getCurrentCPUTime() - startTime);
        if (moduleSpec == null) {
            log.trace("Module %s not found from %s", name, this);
            return null;
        }
        if (!moduleSpec.getName().equals(name)) {
            throw new ModuleLoadException("Module loader found a module with the wrong name");
        }
        final Module module;
        if (moduleSpec instanceof AliasModuleSpec) {
            final String aliasName = ((AliasModuleSpec) moduleSpec).getAliasName();
            try {
                newFuture.setModule(module = loadModuleLocal(name));
            } catch (RuntimeException | Error e) {
                log.trace(e, "Failed to load module %s (alias for %s)", name, aliasName);
                throw e;
            }
        } else {
            module = defineModule((ConcreteModuleSpec) moduleSpec, newFuture);
        }
        log.trace("Loaded module %s from %s", name, this);
        ok = true;
        return module;
    } finally {
        if (!ok) {
            newFuture.setModule(null);
            moduleMap.remove(name, newFuture);
        }
    }
}

[Buggy Hunk]
newFuture.setModule(module = loadModuleLocal(name));

[Patch]
newFuture.setModule(module = loadModuleLocal(aliasName));

[Demonstration 2]

[Buggy Method]
@Test
public void testLoader() throws Exception {
    final File repoRoot = getResource("test/repo");
    final String classPath = "./target/test-classes/test/repo";
    final String deps = "test.test,test.with-deps";
    final String mainClass = "org.jboss.modules.test.TestClass";
    final ModuleLoader moduleLoader = new ClassPathModuleLoader(new LocalModuleLoader(new File[] { repoRoot }), mainClass, classPath, deps);
    Module module = moduleLoader.loadModule(ClassPathModuleLoader.IDENTIFIER);
    module.getClassLoader();
    assertNotNull(module);
}

[Buggy Hunk]
Module module = moduleLoader.loadModule(ClassPathModuleLoader.IDENTIFIER);

[Patch]
Module module = moduleLoader.loadModule(ModuleIdentifier.CLASSPATH);

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