[Demonstration 1]

[Buggy Method]
public Application generate(Service s) {
    List<Method> methods = serviceManager.getServiceMethodsByServiceId(s.getId());
    Application app = new Application();
    Resources resources = new Resources();
    String[] formats = new String[0];
    it.smartcommunitylab.openservices.wadl.ext.Authentication authWadlTag = null;
    if (s.getAccessInformation() != null) {
        resources.setBase(s.getAccessInformation().getEndpoint());
        if (s.getAccessInformation().getFormats() != null) {
            formats = s.getAccessInformation().getFormats().split(",");
        }
        // set authentication fields
        Authentication auth = s.getAccessInformation().getAuthentication();
        if (auth != null) {
            authWadlTag = new it.smartcommunitylab.openservices.wadl.ext.Authentication();
            if (auth.getAccessProtocol().equalsIgnoreCase(AuthProtocol.Public.toString())) {
                authWadlTag.setRequired("false");
            } else {
                authWadlTag.setRequired("true");
                authWadlTag.setValue(auth.getAccessProtocol());
            }
        }
    }
    app.getResources().add(resources);
    // tags
    Tags t = null;
    if (s.getTags() != null) {
        t = new Tags();
        for (Tag tag : s.getTags()) {
            it.smartcommunitylab.openservices.wadl.ext.Tag wadlTag = new it.smartcommunitylab.openservices.wadl.ext.Tag();
            wadlTag.setValue(tag.getName());
            t.getTag().add(wadlTag);
        }
    }
    for (Method m : methods) {
        Resource res = new Resource();
        res.setId(m.getName());
        if (authWadlTag != null) {
            res.getAny().add(authWadlTag);
        }
        if (m.getExecutionProperties() != null) {
            String path = m.getExecutionProperties().getRequestPathTemplate();
            if (path != null) {
                res.setPath(path);
            }
            res = appendWADLNodes(res, path);
            it.smartcommunitylab.openservices.wadl.Method method = new it.smartcommunitylab.openservices.wadl.Method();
            method.setName(m.getExecutionProperties().getHttpMethod());
            method.setId(m.getName());
            Doc doc = new Doc();
            doc.getContent().add(m.getDocumentation());
            if (m.getDocumentation() != null) {
                method.getDoc().add(doc);
            }
            if (t != null) {
                method.getAny().add(t);
            }
            res.getMethodOrResource().add(method);
            Request req = new Request();
            it.smartcommunitylab.openservices.wadl.Response resp = new it.smartcommunitylab.openservices.wadl.Response();
            for (String format : formats) {
                Representation repr = new Representation();
                repr.setMediaType(mediaTypes.get(format) != null ? mediaTypes.get(format) : DEFAULT_MEDIA_TYPE);
                req.getRepresentation().add(repr);
                resp.getRepresentation().add(repr);
            }
            method.setRequest(req);
            method.getResponse().add(resp);
            resources.getResource().add(res);
        }
    }
    return app;
}

[Buggy Hunk]
method.setId(m.getName());

[Patch]
method.setId(method.getName() + "_"+ m.getName());

[Demonstration 2]

[Buggy Method]
private void writeTechFile(Inventory inventory) {
    try (FileWriter writer = new FileWriter(data.getTechnologyFile());
        BufferedWriter buffer = new BufferedWriter(writer)) {
        writeTechMatrix(inventory, buffer);
    } catch (Exception e) {
        log.error("Failed to write technology matrix", e);
    }
}

[Buggy Hunk]
try (FileWriter writer = new FileWriter(data.getTechnologyFile());

[Patch]
try (FileWriter writer = new FileWriter(data.technologyFile);

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