[Demonstration 1]

[Buggy Method]
public String readString() {
    if (isActive()) {
        return client.readStringUntil(BlackJackDemo.EOL);
    }
    return null;
}

[Buggy Hunk]
return client.readStringUntil(BlackJackDemo.EOL);

[Patch]
return client.readStringUntil(BlackJackDemo.EOL).trim();

[Demonstration 2]

[Buggy Method]
@Override
public void factorial() throws RemoteException {
    int result = 1;
    for (int i = (int) m_firstOperand; i > 1; --i) result *= i;
    setCurrentOperand(new Result(result));
}

[Buggy Hunk]
for(int i = (int) m_firstOperand; i > 1; --i)

[Patch]
for(int i = (int) getCurrentOperand(); i > 1; --i)

[Demonstration 3]

[Buggy Method]
protected String[] parseSubjectName(String subject) throws IOException {
    int[] indices = new int[3];
    int last_index = 0;
    // find indices of the $ signs
    for (int i = 0; i < 3; i++) {
        indices[i] = subject.indexOf('$', last_index);
        last_index = indices[i];
        if (last_index == -1) {
            throw new IOException("client name is malformed");
        }
    }
    String username = subject.substring(0, indices[0]);
    String userId = subject.substring(indices[0] + 1, indices[1]);
    String deviceName = subject.substring(indices[1] + 1, indices[2]);
    String deviceId = subject.substring(indices[2] + 1, subject.length());
    return new String[] { username, userId, deviceName, deviceId };
}

[Buggy Hunk]
indices[i] = subject.indexOf('$', last_index);

[Patch]
indices[i] = subject.indexOf('$', last_index + 1);