[Demonstration 1]

[Buggy Method]
@GET
@Override
public Response getPolicies(@HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) {
    PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
    List<Policy> policies;
    try {
        PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
        policies = policyAdministratorPoint.getPolicies();
        if (policies == null || policies.size() == 0) {
            return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
        }
    } catch (PolicyManagementException e) {
        String msg = "ErrorResponse occurred while retrieving all available policies";
        log.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    }
    return Response.status(Response.Status.OK).entity(PolicyFilteringUtil.getPolicies(policies, offset, limit)).build();
}

[Buggy Hunk]
return Response.status(Response.Status.OK).entity(PolicyFilteringUtil.getPolicies(policies, offset, limit))

[Patch]
return Response.status(Response.Status.OK).entity(FilteringUtil.getFilteredList(policies, offset, limit))

[Demonstration 2]

[Buggy Method]
public User replicateUser(String accessToken) {
    GitHubClient gitHubClient = GitHubClient.withAccessToken(accessToken);
    UserResource userInfo = gitHubClient.getUser();
    String login = userInfo.login;
    User user = userRepository.findOne(login);
    if (null == user) {
        user = new User();
        user.setLogin(login);
        String email = userInfo.email;
        if (Strings.isNullOrEmpty(email)) {
            email = gitHubClient.getUserEmails().stream().filter(EmailResource::isVerified).filter(EmailResource::isPrimary).findAny().get().getEmail();
        }
        if (userRepository.exists(Filter.builder().withTarget(User.class).withCondition(builder().eq("email", email).build()).build())) {
            throw new OAuth2AccessDeniedException("User with email '" + email + "' already exists");
        }
        user.setEmail(email.toLowerCase());
        if (!Strings.isNullOrEmpty(userInfo.name)) {
            user.setFullName(userInfo.name);
        }
        User.MetaInfo metaInfo = new User.MetaInfo();
        Date now = Date.from(ZonedDateTime.now().toInstant());
        metaInfo.setLastLogin(now);
        metaInfo.setSynchronizationDate(now);
        user.setMetaInfo(metaInfo);
        user.setType(UserType.GITHUB);
        user.setRole(UserRole.USER);
        Object avatar_url = userInfo.avatarUrl;
        if (null != avatar_url) {
            ResponseEntity<Resource> photoRs = gitHubClient.downloadResource(avatar_url.toString());
            try (InputStream photoStream = photoRs.getBody().getInputStream()) {
                BinaryData photo = new BinaryData(photoRs.getHeaders().getContentType().toString(), photoRs.getBody().contentLength(), photoStream);
                String photoId = dataStorage.saveData(photo, photoRs.getBody().getFilename());
                user.setPhotoId(photoId);
            } catch (IOException e) {
                LOGGER.error("Unable to load photo for user {}", login);
            }
        }
        user.setIsExpired(false);
        user.setDefaultProject(generatePersonalProject(user).getId());
        userRepository.save(user);
    }
    return user;
}

[Buggy Hunk]
throw new OAuth2AccessDeniedException("User with email '" + email + "' already exists");

[Patch]
throw new EmailAlreadyExistsException("User with email '" + email + "' already exists");

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