[Demonstration 1]

[Buggy Method]
public static Session getSSHSession(AuthenticationInfo authenticationInfo, ServerInfo serverInfo) throws AiravataException {
    SSHKeyAuthentication authentication = null;
    String key = serverInfo.getUserName() + "_" + serverInfo.getHost() + "_" + serverInfo.getPort();
    Session session = sessionMap.get(key);
    boolean valid = isValidSession(session);
    // FIXME - move following info logs to debug
    if (valid) {
        log.info("SSH Session validation succeeded, key :" + key);
        valid = testChannelCreation(session);
        if (valid) {
            log.info("Channel creation test succeeded, key :" + key);
        } else {
            log.info("Channel creation test failed, key :" + key);
        }
    } else {
        log.info("Session validation failed, key :" + key);
    }
    if (!valid) {
        if (session != null) {
            log.info("Reinitialize a new SSH session for :" + key);
        } else {
            log.info("Initialize a new SSH session for :" + key);
        }
        try {
            if (authenticationInfo instanceof SSHKeyAuthentication) {
                authentication = (SSHKeyAuthentication) authenticationInfo;
            } else {
                throw new AiravataException("Support ssh key authentication only");
            }
            JSch jSch = new JSch();
            jSch.addIdentity(UUID.randomUUID().toString(), authentication.getPrivateKey(), authentication.getPublicKey(), authentication.getPassphrase().getBytes());
            session = jSch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort());
            session.setUserInfo(new DefaultUserInfo(serverInfo.getUserName(), null, authentication.getPassphrase()));
            if (authentication.getStrictHostKeyChecking().equals("yes")) {
                jSch.setKnownHosts(authentication.getKnownHostsFilePath());
            } else {
                session.setConfig("StrictHostKeyChecking", "no");
            }
            // 0 connection timeout
            session.connect();
            sessionMap.put(key, session);
        } catch (JSchException e) {
            throw new AiravataException("JSch initialization error ", e);
        }
    } else {
        // FIXME - move following info log to debug
        log.info("Reuse SSH session for :" + key);
    }
    return sessionMap.get(key);
}

[Buggy Hunk]
public static Session getSSHSession(AuthenticationInfo authenticationInfo, ServerInfo serverInfo) throws AiravataException {

[Patch]
public static synchronized Session getSSHSession(AuthenticationInfo authenticationInfo, ServerInfo serverInfo) throws AiravataException {

[Demonstration 2]

[Buggy Method]
private void handleDataCreated(Map<InstanceIdentifier<?>, DataObject> createdData) {
    Preconditions.checkNotNull(createdData);
    if (!createdData.isEmpty()) {
        // TODO: put this on a new thread, or make the algorithm below fully async
        for (Map.Entry<InstanceIdentifier<?>, DataObject> dataObjectEntry : createdData.entrySet()) {
            final InstanceIdentifier<Node> path = (InstanceIdentifier<Node>) dataObjectEntry.getKey();
            // sleep 250ms and then re-read the Node information to give OF a change to update with FlowCapable
            // TODO: Figure out why FlowCapableNode is attached later. Who adds the original Node?
            executorService.schedule(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
                    final CheckedFuture<Optional<Node>, ReadFailedException> readFuture = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, path);
                    Futures.addCallback(readFuture, new FutureCallback<Optional<Node>>() {

                        @Override
                        public void onSuccess(Optional<Node> result) {
                            if (result.isPresent()) {
                                identifyDevice(path, result.get());
                            } else {
                                LOG.error("Read succeeded, node doesn't exist: {}", path);
                            }
                        }

                        @Override
                        public void onFailure(Throwable t) {
                            LOG.error("Failed to read Node: {}", path, t);
                        }
                    });
                    return null;
                }
            }, 250, TimeUnit.MILLISECONDS);
        }
    }
}

[Buggy Hunk]
executorService.schedule(new Callable<Void>() {

[Patch]
EXECUTORSERVICE.schedule(new Callable<Void>() {

[Demonstration 3]

[Buggy Method]
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    /*
	   * Check if request is not refer to CGI-IDP - ignore it;
      */
    if (!isFilteredRequest(request) || !filterConfig.isEnabled()) {
        log.debug("According to {} configuration parameter request is ignored + {}", new Object[] { FilterConfig.EXCLUDED_URL_PATTERN_PARAMETER, request.getRequestURI() });
        chain.doFilter(servletRequest, servletResponse);
        return;
    }
    log.debug("Attempt to secure resource  is intercepted : {}", request.getRequestURL().toString());
    /*
		  Check if response message is received from identity provider;
          In case of successful response system redirects user to relayState (initial) request
        */
    String responseMessage = servletRequest.getParameter(SAML_AUTHN_RESPONSE_PARAMETER_NAME);
    String spProviderId = filterConfig.getSpProviderId();
    if (responseMessage != null) {
        log.debug("Response from Identity Provider is received");
        try {
            log.debug("Decoding of SAML message");
            SAMLMessageContext samlMessageContext = SAMLUtils.decodeSamlMessage(request, response);
            log.debug("SAML message has been decoded successfully");
            samlMessageContext.setLocalEntityId(spProviderId);
            //String relayState = getInitialRequestedResource(samlMessageContext);
            checkSAMLResponse.verify(samlMessageContext);
            log.debug("Starting and store SAML session..");
            SAMLSessionManager.getInstance().createSAMLSession(request, response, samlMessageContext);
            // log.debug("User has been successfully authenticated in idP. Redirect to initial requested resource {}", relayState);
            //response.sendRedirect(relayState);
            return;
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }
    /*
        * Check if request is logout request
        */
    if (this.getCorrectURL(request).equals(this.filterConfig.getLogoutUrl())) {
        log.debug("Logout action: destroying SAML session.");
        try {
            SAMLSessionInfo samlSessionInfo = SAMLSessionManager.getInstance().getSAMLSession(request.getSession());
            samlRequestSender.sendSAMLLogoutRequest(request, response, spProviderId, filterConfig.getIdpSSOLogoutUrl(), samlSessionInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        SAMLSessionManager.getInstance().destroySAMLSession(request.getSession());
    }
    /*
        *   Check if user has already authorised
        */
    if (SAMLSessionManager.getInstance().isSAMLSessionValid(request.getSession())) {
        SAMLSessionInfo samlSessionInfo = SAMLSessionManager.getInstance().getSAMLSession(request.getSession());
        SAMLSessionManager.getInstance().loginUser(samlSessionInfo, request, response);
        log.debug("SAML session exists and valid: grant access to secure resource");
        //chain.doFilter(request, response);
        return;
    }
    /*
        * Create SAML request and redirect user to CGI service for authentication
         */
    log.debug("Sending authentication request to idP");
    try {
        samlRequestSender.sendSAMLAuthRequest(request, response, spProviderId, filterConfig.getAcsUrl(), filterConfig.getIdpSSOLoginUrl());
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

[Buggy Hunk]
SAMLMessageContext samlMessageContext =

[Patch]
SAMLMessageContext<Response, SAMLObject, NameID> samlMessageContext =