[Demonstration 1]

[Buggy Method]
@Override
public Dashboard remoteCreate(DashboardRemoteRequest request) throws HygieiaException {
    Dashboard dashboard;
    if (userInfoService.isUserValid(request.getMetaData().getOwner().getUsername(), request.getMetaData().getOwner().getAuthType())) {
        throw new HygieiaException("Invalid owner information or authentication type. Owner first needs to sign up in Hygieia", HygieiaException.BAD_DATA);
    }
    List<Dashboard> dashboards = dashboardRepository.findByTitle(request.getMetaData().getTitle());
    if (!CollectionUtils.isEmpty(dashboards)) {
        dashboard = dashboards.get(0);
        //not right
        dashboard.getWidgets().clear();
    } else {
        dashboard = dashboardService.create(requestToDashboard(request));
    }
    List<DashboardRemoteRequest.Entry> entries = request.getAllEntries();
    Map<String, WidgetRequest> allWidgetRequests = new HashMap<>();
    for (DashboardRemoteRequest.Entry entry : entries) {
        List<Collector> collectors = collectorRepository.findByCollectorTypeAndName(entry.getType(), entry.getToolName());
        if (CollectionUtils.isEmpty(collectors)) {
            throw new HygieiaException(entry.getToolName() + " collector is not available.", HygieiaException.BAD_DATA);
        }
        Collector collector = collectors.get(0);
        WidgetRequest widgetRequest = allWidgetRequests.get(entry.getWidgetName());
        if (widgetRequest == null) {
            widgetRequest = entryToWidgetRequest(dashboard, entry, collector);
            allWidgetRequests.put(entry.getWidgetName(), widgetRequest);
        } else {
            CollectorItem item = entryToCollectorItem(entry, collector);
            if (item != null) {
                widgetRequest.getCollectorItemIds().add(item.getId());
            }
        }
    }
    for (String key : allWidgetRequests.keySet()) {
        WidgetRequest widgetRequest = allWidgetRequests.get(key);
        Component component = dashboardService.associateCollectorToComponent(dashboard.getApplication().getComponents().get(0).getId(), widgetRequest.getCollectorItemIds());
        dashboardService.addWidget(dashboard, widgetRequest.widget());
    }
    return (dashboard != null) ? dashboardService.get(dashboard.getId()) : null;
}

[Buggy Hunk]
if (userInfoService.isUserValid(request.getMetaData().getOwner().getUsername(), request.getMetaData().getOwner().getAuthType())) {

[Patch]
if (!userInfoService.isUserValid(request.getMetaData().getOwner().getUsername(), request.getMetaData().getOwner().getAuthType())) {

[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]
@GET
@Path("/getDatasetDashboard")
@Produces(MediaType.APPLICATION_JSON)
public Response getDatasetDashboard(@Context HttpServletRequest request) {
    HttpSession session = request.getSession();
    String accessToken = (String) session.getAttribute("access_token");
    String refreshToken = (String) session.getAttribute("refresh_token");
    if (accessToken == null) {
        return Response.status(401).build();
    }
    String username = (String) session.getAttribute("user");
    dashboardGenerator dashboardGenerator = new dashboardGenerator(accessToken, refreshToken);
    String dashboard = dashboardGenerator.getDashboard(username);
    return Response.ok("{\"dashboard\": \"" + dashboard + "\"}").build();
}

[Buggy Hunk]
String dashboard = dashboardGenerator.getDashboard(username);

[Patch]
String dashboard = dashboardGenerator.getDashboard();