[Demonstration 1]

[Buggy Method]
public static void main(String[] args) {
    Server server = new Server();
    server.addShutdownHook();
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            server.openSocket(3000);
            server.startReceiveThread();
            ;
        }
    });
    thread.start();
}

[Buggy Hunk]
server.openSocket(3000);

[Patch]
server.openSocket(LISTEN_PORT);

[Demonstration 2]

[Buggy Method]
@Test
public void when_searching_result_is_of_desired_size() throws Exception {
    NameIndexer nameIndexer = new NameIndexer(new InputStreamReader(getClass().getResourceAsStream("/somePersons.json")));
    assertThat(nameIndexer.neighbourhoodOf("Hansen, T.", 10).size(), equalTo(10));
}

[Buggy Hunk]
assertThat(nameIndexer.neighbourhoodOf("Hansen, T.", 10).size(), equalTo(10));

[Patch]
assertThat(nameIndexer.neighbourhoodOf("Hansen, T.", SMALL_LENGTH).size(), equalTo(SMALL_LENGTH));

[Demonstration 3]

[Buggy Method]
long dumpData(FileOutputStream dumpOut, RandomAccessFile raf) throws IOException {
    if (dataState != DataState.ALLOW_DUMP) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("No need to dump with status(replied,dataState):" + "(" + replied + "," + dataState + ")");
        }
        return 0;
    }
    // Resized write should not allow dump
    Preconditions.checkState(originalCount == INVALID_ORIGINAL_COUNT);
    this.raf = raf;
    dumpFileOffset = dumpOut.getChannel().position();
    dumpOut.write(data.array(), 0, count);
    if (LOG.isDebugEnabled()) {
        LOG.debug("After dump, new dumpFileOffset:" + dumpFileOffset);
    }
    // it is possible that while we dump the data, the data is also being
    // written back to HDFS. After dump, if the writing back has not finished
    // yet, we change its flag to DUMPED and set the data to null. Otherwise
    // this WriteCtx instance should have been removed from the buffer.
    if (dataState == DataState.ALLOW_DUMP) {
        synchronized (this) {
            if (dataState == DataState.ALLOW_DUMP) {
                data = null;
                dataState = DataState.DUMPED;
                return count;
            }
        }
    }
    return 0;
}

[Buggy Hunk]
Preconditions.checkState(originalCount == INVALID_ORIGINAL_COUNT);

[Patch]
Preconditions.checkState(getOriginalCount() == INVALID_ORIGINAL_COUNT);