[Demonstration 1]

[Buggy Method]
@Override
public boolean validateGrant(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception {
    boolean validGrant = super.validateGrant(tokReqMsgCtx);
    if (!validGrant) {
        return false;
    }
    String token = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getWindowsToken();
    IWindowsSecurityContext serverContext = null;
    if (token != null) {
        byte[] bytesToken = Base64.decode(token);
        int tokenType = getNLTMMessageType(bytesToken);
        if (log.isDebugEnabled()) {
            log.debug("Received NTLM token Type " + tokenType + ":" + token);
        }
        if (tokenType == NTLM_TYPE_1_TOKEN) {
            serverContext = provider.acceptSecurityToken(SERVER_CONNECTION, bytesToken, SECURITY_PACKAGE);
            String type2Token = Base64.encode(serverContext.getToken());
            if (log.isDebugEnabled()) {
                log.debug("Sent NTLM token Type 2:" + type2Token);
            }
            ResponseHeader[] responseHeaders = new ResponseHeader[1];
            responseHeaders[0] = new ResponseHeader();
            responseHeaders[0].setKey(HEADER_WWW_AUTHENTICATE);
            responseHeaders[0].setValue(SCHEME_NTLM + " " + type2Token);
            tokReqMsgCtx.addProperty(RESPONSE_HEADERS_PROPERTY, responseHeaders);
            return false;
        } else if (tokenType == NTLM_TYPE_3_TOKEN) {
            serverContext = provider.acceptSecurityToken(SERVER_CONNECTION, bytesToken, SECURITY_PACKAGE);
            String resourceOwnerUserNameWithDomain = serverContext.getIdentity().getFqn();
            String resourceOwnerUserName = resourceOwnerUserNameWithDomain.split("\\\\")[1];
            tokReqMsgCtx.setAuthorizedUser(OAuth2Util.getUserFromUserName(resourceOwnerUserName));
            return true;
        } else {
            log.error("Unknown NTLM token, Type " + tokenType + ":" + token);
            return false;
        }
    } else {
        throw new IdentityOAuth2Exception("Received NTLM token is null");
    }
}

[Buggy Hunk]
tokReqMsgCtx.addProperty(RESPONSE_HEADERS_PROPERTY, responseHeaders);

[Patch]
tokReqMsgCtx.addProperty(OAuthConstants.RESPONSE_HEADERS_PROPERTY, responseHeaders);

[Demonstration 2]

[Buggy Method]
@RequestMapping(value = "/uploadPic", method = RequestMethod.POST)
public ModelAndView uploadPic(Model model, PhotoUpload uploadItem, HttpServletRequest request, HttpServletResponse response) throws IOException {
    MultipartFile file = uploadItem.getFileData();
    InputStream inputStream = null;
    //	OutputStream outputStream = null;
    if (file.getSize() > 0)
        inputStream = file.getInputStream();
    byte[] imageData = IOUtils.toByteArray(inputStream);
    HttpSession session = request.getSession();
    ResourceMaster resource = (ResourceMaster) session.getAttribute("resource");
    Long employeeId = resource.getEmployeeId();
    int count = 0;
    count = employeeServiceImpl.uploadEmployeePicture(imageData, employeeId);
    ModelAndView modelandview = new ModelAndView();
    if (count == 1)
        modelandview.addObject("photoUpload", "success");
    else
        modelandview.addObject("photoUpload", "failure");
    byte[] encodeBase64 = Base64.encode(imageData);
    String base64Encoded = new String(encodeBase64, "UTF-8");
    resource.setBase64Jmage(base64Encoded);
    session.setAttribute("resource", resource);
    modelandview.setViewName("myPersonaldetails");
    return modelandview;
}

[Buggy Hunk]
byte[] encodeBase64 = Base64.encode(imageData);

[Patch]
byte[] encodeBase64 = Base64.getEncoder().encode(imageData);/*encode(imageData);*/

[Demonstration 3]

[Buggy Method]
public void onClick(View v) {
    List<? extends Nameable> nameables = getNameableList(type);
    SelectNameableDialog dialog = new SelectNameableDialog(CreateLessonActivityNew.this, nameables, type);
    dialog.show();
    dialog.setOnDismissListener(onSelectionDialogDismiss);
}

[Buggy Hunk]
SelectNameableDialog dialog = new SelectNameableDialog(CreateLessonActivityNew.this, nameables, type);

[Patch]
SelectNameableDialog dialog = new SelectNameableDialog(CreateLessonActivity.this, nameables, type);