[Demonstration 1]

[Buggy Method]
public static String generateHashCode(@Nonnull File file) {
    if (!file.isFile()) {
        return null;
    }
    MessageDigest digest = null;
    // why do stream twice for a single resource?
    // --> we can't generate the hashCode adhoc when we stream the data to the client
    // since the hash code needs to be send first in the header response
    // --> to avoid this stream we could read all the content of the resource first into memory
    // but no one knows how big this data is.
    // so better stream twice if necessary
    try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
        byte[] array = new byte[4];
        digest = MessageDigest.getInstance("MD5");
        for (int data = in.read(array); data != -1; data = in.read()) {
            // we better read a single byte since this will crop off all other left-handed bits
            digest.update(array);
        }
    } catch (NoSuchAlgorithmException | IOException e) {
        throw new IllegalStateException(String.format("Unable to generate hash code for %s: ", file), e);
    }
    String hashCode = DatatypeConverter.printHexBinary(digest.digest());
    return hashCode;
}

[Buggy Hunk]
for (int data = in.read(array); data != -1; data = in.read()) {

[Patch]
for (int data = in.read(array); data != -1; data = in.read(array)) {

[Demonstration 2]

[Buggy Method]
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    in.read(length, 0, 4);
    type = (byte) in.read();
    int messageLength = ByteBuffer.wrap(length).getInt();
    payload = new byte[messageLength - 1];
    in.read(payload, 0, messageLength);
}

[Buggy Hunk]
in.read(payload, 0, messageLength);

[Patch]
in.read(payload, 0, messageLength - 1);

[Demonstration 3]

[Buggy Method]
public void applySnapshot(RuntimeEngineState snapshot) {
    if (snapshot == null) {
        throw new IllegalArgumentException("Snapshot cannot be null");
    }
    setStatus(snapshot.getStatus());
    currentTags = new StringMapFormat().parseCompoundValue(model.getSpaceRoot(), snapshot.getSerializedTagValue());
    currentNode = decisionGraph.getNode(snapshot.getCurrentNodeId());
    stack.clear();
    snapshot.getStack().forEach((nodeId) -> stack.push((CallNode) decisionGraph.getNode(nodeId)));
}

[Buggy Hunk]
snapshot.getStack().forEach((nodeId) -> stack.push((CallNode) decisionGraph.getNode(nodeId)));

[Patch]
snapshot.getStack().forEach((nodeId) -> stack.push((ThroughNode) decisionGraph.getNode(nodeId)));