[Demonstration 1]

[Buggy Method]
public boolean finish(Euler simulator) {
    InternalBackendData bed = (InternalBackendData) equations.backendData;
    // Events
    for (EventSource es : bed.eventSources) {
        @SuppressWarnings("unchecked")
        ArrayList<Instance> monitors = (ArrayList<Instance>) valuesObject[es.valueIndex];
        EventTarget eventType = es.target;
        if (eventType.testAll) {
            for (Instance i : monitors) {
                double delay = eventType.test(i, simulator);
                // the trigger condition was not satisfied
                if (delay == -2)
                    continue;
                EventSpikeSingle spike;
                if (delay >= 0) {
                    // : new EventSpikeSingleLatch ();
                    spike = new EventSpikeSingle();
                    spike.t = simulator.currentEvent.t + delay;
                } else // delay == -1 --> event was triggered, but timing is no-care
                {
                    spike = new EventSpikeSingleLatch();
                    // queue immediately after current cycle, so latches get set for next full cycle
                    spike.t = simulator.currentEvent.t;
                }
                spike.eventType = eventType;
                simulator.eventQueue.add(spike);
            }
        } else if (monitors.size() > 0) {
            double delay = eventType.test(monitors.get(0), simulator);
            if (// the trigger condition was satisfied
            delay >= -1) {
                EventSpikeMulti spike;
                if (delay >= 0) {
                    spike = new EventSpikeMulti();
                    spike.t = simulator.currentEvent.t + delay;
                } else {
                    spike = new EventSpikeMultiLatch();
                    spike.t = simulator.currentEvent.t;
                }
                spike.eventType = eventType;
                // We don't copy the array, just keep a reference to it. What could go wrong with this?
                // If a part dies and tries to remove itself from the list while it is being used to deliver spikes,
                // then we could get a null pointer exception. Solution is to synchronize access to the list.
                // If a connection is born while the spike is in flight, one could argue that it shouldn't
                // receive it, but one could also argue that it should. In nature these two things (spikes
                // and synapse creation) occur at vastly different timescales. Wouldn't a nascent synapse
                // receive spikes even as it is forming?
                spike.targets = monitors;
                simulator.eventQueue.add(spike);
            }
        }
    }
    // Other stuff
    if (populations != null)
        for (Population p : populations) p.finish(simulator);
    if (bed.liveStorage == InternalBackendData.LIVE_STORED) {
        // early-out if we are already dead, to avoid another call to die()
        if (((Scalar) get(bed.live)).value == 0)
            return false;
    }
    if (bed.lastT != null)
        setFinal(bed.lastT, new Scalar(simulator.currentEvent.t));
    for (Variable v : bed.localBufferedExternal) setFinal(v, getFinal(v));
    for (Integer i : bed.eventLatches) valuesFloat[i] = 0;
    for (Variable v : bed.localBufferedExternalWrite) {
        switch(v.assignment) {
            case Variable.ADD:
                // initial value is zero-equivalent (additive identity)
                set(v, v.type);
                break;
            // TODO: make the following cases type-sensitive
            case Variable.MULTIPLY:
                // multiplicative identity
                set(v, new Scalar(1));
                break;
            case Variable.MIN:
                set(v, new Scalar(Double.POSITIVE_INFINITY));
                break;
            case Variable.MAX:
                set(v, new Scalar(Double.NEGATIVE_INFINITY));
                break;
        }
    }
    if (bed.type != null) {
        int type = (int) ((Scalar) get(bed.type)).value;
        if (type > 0) {
            ArrayList<EquationSet> split = equations.splits.get(type - 1);
            if (// Make sure $type != me. Otherwise it's a null operation
            split.size() > 1 || split.get(0) != equations) {
                // indicates that this instance is one of the resulting parts
                boolean used = false;
                int countParts = split.size();
                for (int i = 0; i < countParts; i++) {
                    EquationSet other = split.get(i);
                    Scalar splitPosition = new Scalar(i + 1);
                    if (other == equations && !used) {
                        used = true;
                        setFinal(bed.type, splitPosition);
                    } else {
                        Part p = convert(other);
                        enqueue(p);
                        p.resolve();
                        // accountable connections are updated here
                        p.init(simulator);
                        // Copy over variables
                        Conversion conversion = bed.conversions.get(other);
                        int count = conversion.from.size();
                        for (int v = 0; v < count; v++) {
                            Variable from = conversion.from.get(v);
                            Variable to = conversion.to.get(v);
                            p.setFinal(to, get(from));
                        }
                        // Set $type to be our position in the split
                        InternalBackendData otherBed = (InternalBackendData) other.backendData;
                        p.setFinal(otherBed.type, splitPosition);
                    }
                }
                if (!used) {
                    die();
                    return false;
                }
            }
        }
    }
    if (equations.lethalP) {
        double p;
        if (bed.p.hasAttribute("temporary")) {
            InstanceTemporaries temp = new InstanceTemporaries(this, simulator, false);
            p = ((Scalar) bed.p.eval(temp)).value;
        } else {
            p = ((Scalar) get(bed.p)).value;
        }
        if (p == 0 || p < 1 && p < simulator.uniform.nextDouble()) {
            die();
            return false;
        }
    }
    if (equations.lethalConnection) {
        int count = equations.connectionBindings.size();
        for (int i = 0; i < count; i++) {
            if (!getPart(i).getLive()) {
                die();
                return false;
            }
        }
    }
    if (equations.lethalContainer) {
        if (!((Part) container.container).getLive()) {
            die();
            return false;
        }
    }
    return true;
}

[Buggy Hunk]
ArrayList<Instance> monitors = (ArrayList<Instance>) valuesObject[es.valueIndex];

[Patch]
ArrayList<Instance> monitors = (ArrayList<Instance>) valuesObject[es.monitorIndex];

[Demonstration 2]

[Buggy Method]
public void run() {
    try {
        appNotification.notifyUser(vote.getObjectId(), Vote.class, vote.getId(), User.class, vote.getObjectId());
    } catch (SocialErrorException ex) {
        logger.warn("error happens when notifying new vote", ex);
    }
    int defaultMaxScore = MAX_SCORE;
    Setting setting = appSetting.getSetting(1, "default_max_vote_score");
    if (setting != null) {
        defaultMaxScore = Ints.tryParse(setting.getValue());
    }
    if (vote.getScore() == defaultMaxScore) {
        appSocialEmail.addEmail(vote.getObjectId(), EmailActionTypes.FIVE_STARS_VOTE);
    }
}

[Buggy Hunk]
appSocialEmail.addEmail(vote.getObjectId(), EmailActionTypes.FIVE_STARS_VOTE);

[Patch]
appSocialEmail.addEmail(vote.getObjectId(), EmailActionTypes.MOST_STARS_VOTE);

[Demonstration 3]

[Buggy Method]
List<Listener> listeners(String event) {
    LinkedList<Listener> callbacks = this.callbacks.get(event);
    return callbacks != null ? new ArrayList<>(callbacks) : new ArrayList<>(0);
}

[Buggy Hunk]
new ArrayList<>(callbacks) : new ArrayList<>(0);

[Patch]
new ArrayList<Listener>(callbacks) : new ArrayList<Listener>(0);