[Demonstration 1]

[Buggy Method]
@Override
public synchronized void execute() throws ModbusException {
    if (request == null || connection == null) {
        throw new ModbusException("Invalid request or connection");
    }
    // Automatically re-connect if disconnected.
    if (!connection.isConnected()) {
        try {
            logger.debug("connecting to: {}", connection.getAddress().toString());
            connection.connect();
            transport = connection.getModbusTransport();
        } catch (Exception ex) {
            throw new ModbusIOException("Connection failed", ex);
        }
    }
    // Try sending the message up to retries time. Note that the message
    // is read immediately after being written, with no flushing of buffers.
    int retryCounter = 0;
    int retryLimit = (retries > 0 ? retries : 1);
    transport.setTimeout(connection.getTimeout());
    while (retryCounter < retryLimit) {
        try {
            logger.debug("request transaction ID = {}", request.getTransactionID());
            transport.writeMessage(request);
            response = null;
            do {
                response = transport.readResponse();
                if (logger.isDebugEnabled()) {
                    logger.debug("response transaction ID = {}, RESPONSE: {}", response.getTransactionID(), response.getHexMessage());
                    if (response.getTransactionID() != request.getTransactionID()) {
                        logger.debug("expected {}, got {}", request.getTransactionID(), response.getTransactionID());
                    }
                }
            } while (// We need to keep retrying if;
            //   a) the response is empty or
            //   b) we have been told to check the validity and the request/response transaction IDs don't match AND
            //   c) we haven't exceeded the maximum retry count
            (response == null || (validityCheck && (request.getTransactionID() != 0 && request.getTransactionID() != response.getTransactionID()))) && ++retryCounter < retryLimit);
            if (retryCounter >= retryLimit) {
                throw new ModbusIOException("Executing transaction failed (tried {} times)", retryLimit);
            }
            // Both methods were successful, so the transaction must
            // have been executed.
            break;
        } catch (ModbusIOException ex) {
            if (!connection.isConnected()) {
                try {
                    connection.connect();
                } catch (Exception e) {
                    // Nope, fail this transaction.
                    throw new ModbusIOException("Connection lost", e);
                }
            }
            retryCounter++;
            if (retryCounter >= retryLimit) {
                throw new ModbusIOException("Executing transaction failed (tried {}" + retryLimit + " times)", ex);
            }
        }
    }
    // The slave may have returned an exception -- check for that.
    if (response instanceof ExceptionResponse) {
        throw new ModbusSlaveException(((ExceptionResponse) response).getExceptionCode());
    }
    // Close the connection if it isn't supposed to stick around.
    if (isReconnecting()) {
        connection.close();
    }
    // See if packets require validity checking.
    if (isCheckingValidity()) {
        checkValidity();
    }
    incrementTransactionID();
}

[Buggy Hunk]
throw new ModbusIOException("Executing transaction failed (tried {}" + retryLimit + " times)", ex);

[Patch]
throw new ModbusIOException("Executing transaction failed (tried {} times) {}", retryLimit, ex);

[Demonstration 2]

[Buggy Method]
@Override
protected ListenableFuture<HttpResponse> invokeAsync(final Request nativeRequest) {
    OkHttpClient requestScopedClient = globalClient.clone();
    try {
        requestScopedClient.setProxy(proxyForURI.apply(nativeRequest.uri()));
    } catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
    SettableFuture<Response> responseFuture = SettableFuture.create();
    requestScopedClient.newCall(nativeRequest).enqueue(new Callback() {

        @Override
        public void onResponse(Response response) throws IOException {
            responseFuture.set(response);
        }

        @Override
        public void onFailure(Request request, IOException ex) {
            responseFuture.setException(ex);
        }
    });
    return Futures.transform(responseFuture, responseTransformer);
}

[Buggy Hunk]
SettableFuture<Response> responseFuture = SettableFuture.create();

[Patch]
final SettableFuture<Response> responseFuture = SettableFuture.create();

[Demonstration 3]

[Buggy Method]
@Override
public void handleError(ForestRequest request, ForestResponse response, Exception ex) {
    ForestRuntimeException e = null;
    if (ex instanceof ForestRuntimeException) {
        e = (ForestRuntimeException) ex;
    } else {
        e = new ForestRuntimeException(ex);
    }
    request.getInterceptorChain().onError(e, request, response);
    if (request.getOnError() != null) {
        request.getOnError().onError(e, request);
    } else {
        throw e;
    }
}

[Buggy Hunk]
request.getOnError().onError(e, request);

[Patch]
request.getOnError().onError(e, request, response);