[Demonstration 1]

[Buggy Method]
public void addSession(Session session) {
    synchronized (this.sessions) {
        if (this.sessions.contains(session)) {
            return;
        }
        this.sessions.add(session);
        this.sessionHeartbeats.add(new AtomicLong(Clock.currentTimeMillis()));
    }
}

[Buggy Hunk]
this.sessionHeartbeats.add(new AtomicLong(Clock.currentTimeMillis()));

[Patch]
this.sessionHeartbeats.put(session.getId(), Clock.currentTimeMillis());

[Demonstration 2]

[Buggy Method]
@Override
public double getValue(String eventURI, List<Keyword> keywords, UserModel userModel) {
    double result;
    switch(this.keywordAggregationType) {
        case AGGREGATION_TYPE_MIN:
            result = Double.POSITIVE_INFINITY;
            break;
        case AGGREGATION_TYPE_GEOM:
            result = 1.0;
            break;
        case AGGREGATION_TYPE_MAX:
            result = Double.NEGATIVE_INFINITY;
            break;
        case AGGREGATION_TYPE_AVG:
        default:
            result = 0.0;
            break;
    }
    List<Keyword> keywordsToUse = useUserInterestsInsteadOfQuery ? userModel.getInterests() : keywords;
    Set<String> comparisonStrings = getComparisonStrings(eventURI, keywordsToUse, userModel);
    if (comparisonStrings.isEmpty()) {
        if (this.shouldWarnIfNoComparisonStrings && log.isWarnEnabled())
            log.warn(String.format("no comparisonStrings for event '%s', returning 0", eventURI));
        return 0;
    }
    List<double[]> sentenceVectors = new ArrayList<double[]>();
    for (String sentence : comparisonStrings) {
        if (sentence.isEmpty())
            continue;
        String preprocessed = embeddings.getUseLowercase() ? sentence.toLowerCase() : sentence;
        Sentence s = new Sentence(preprocessed);
        List<String> contentWords = new ArrayList<String>();
        for (String word : s.words()) {
            if (// filter out stop words
            !this.stopWords.contains(word.toLowerCase()))
                contentWords.add(word);
        }
        double[] vector = embeddings.wordsToVector(contentWords);
        if (vector != null)
            sentenceVectors.add(vector);
    }
    for (Keyword keyword : keywordsToUse) {
        double keywordResult;
        switch(this.innerAggregationType) {
            case AGGREGATION_TYPE_MIN:
                keywordResult = Double.POSITIVE_INFINITY;
                break;
            case AGGREGATION_TYPE_GEOM:
                keywordResult = 1.0;
                break;
            case AGGREGATION_TYPE_MAX:
                keywordResult = Double.NEGATIVE_INFINITY;
                break;
            case AGGREGATION_TYPE_AVG:
            default:
                keywordResult = 0.0;
                break;
        }
        // preprocess the keyword string as required by embeddings
        String preprocessed = embeddings.getUseLowercase() ? keyword.getWord().toLowerCase() : keyword.getWord();
        List<String> keywordTokens = new ArrayList<String>();
        if (embeddings.getSplitKeywordsIntoTokens())
            keywordTokens.addAll(Arrays.asList(preprocessed.split(" ")));
        else {
            if (embeddings.hasWord(preprocessed.replace(" ", "_")))
                keywordTokens.add(preprocessed.replace(" ", "_"));
            else
                keywordTokens.addAll(Arrays.asList(preprocessed.split(" ")));
        }
        List<String> keywordContentTokens = new ArrayList<String>();
        for (String keywordToken : keywordTokens) {
            if (// filter out stop words in case we split the label
            !this.stopWords.contains(keywordToken))
                keywordContentTokens.add(keywordToken);
        }
        double[] keywordVector = embeddings.wordsToVector(keywordContentTokens);
        if (keywordVector == null)
            continue;
        for (double[] sentenceVector : sentenceVectors) {
            double similarity = EmbeddingsProvider.cosineSimilarity(keywordVector, sentenceVector);
            switch(this.innerAggregationType) {
                case AGGREGATION_TYPE_AVG:
                    keywordResult += similarity / sentenceVectors.size();
                    break;
                case AGGREGATION_TYPE_MAX:
                    keywordResult = Math.max(keywordResult, similarity);
                    break;
                case AGGREGATION_TYPE_MIN:
                    keywordResult = Math.min(keywordResult, similarity);
                    break;
                case AGGREGATION_TYPE_GEOM:
                    keywordResult *= similarity;
                    break;
                default:
                    break;
            }
        }
        if (this.innerAggregationType == AGGREGATION_TYPE_GEOM)
            keywordResult = Math.pow((keywordResult > 0) ? keywordResult : -keywordResult, (1.0 / sentenceVectors.size()));
        switch(this.keywordAggregationType) {
            case AGGREGATION_TYPE_AVG:
                result += keywordResult / keywordsToUse.size();
                break;
            case AGGREGATION_TYPE_MAX:
                result = Math.max(result, keywordResult);
                break;
            case AGGREGATION_TYPE_MIN:
                result = Math.min(result, keywordResult);
                break;
            case AGGREGATION_TYPE_GEOM:
                result *= keywordResult;
                break;
            default:
                break;
        }
    }
    if (this.keywordAggregationType == AGGREGATION_TYPE_GEOM)
        result = Math.pow((result > 0) ? result : -result, (1.0 / keywordsToUse.size()));
    if (Double.isInfinite(result))
        result = 0;
    return result;
}

[Buggy Hunk]
Set<String> comparisonStrings = getComparisonStrings(eventURI, keywordsToUse, userModel);

[Patch]
Set<String> comparisonStrings = getComparisonStrings(eventURI, keywords, userModel);

[Demonstration 3]

[Buggy Method]
public static void register(JavaPlugin plugin, LocalMaps localMaps) {
    PluginCommand command = plugin.getCommand("exomaps");
    command.setExecutor(new CommandRegistration(localMaps));
    command.setPermission("exorath.maps.cmd");
}

[Buggy Hunk]
command.setExecutor(new CommandRegistration(localMaps));

[Patch]
command.setExecutor(new CommandRegistration(plugin, localMaps));