[Demonstration 1]

[Buggy Method]
@Override
public void write(byte[] b, int off, int len) throws IOException {
    out.write(b, off, len);
    count += len;
}

[Buggy Hunk]
count+=len;

[Patch]
if(len > 0) count += len;

[Demonstration 2]

[Buggy Method]
@Override
public void write(byte[] b, int off, int len) throws IOException {
    for (OutputStream outputStream : out) {
        outputStream.write(b, off, len);
    }
}

[Buggy Hunk]
public void write(byte[] b, int off, int len) throws IOException {

[Patch]
synchronized public void write(byte[] b, int off, int len) throws IOException {

[Demonstration 3]

[Buggy Method]
@Override
public String getLogin() {
    try {
        startHttpClient(httpClient);
        // Build request body
        LoginForm loginForm = new LoginForm(true, mUsername, mPassword, false, 1);
        Request request = httpClient.newRequest(getZAutomationTopLevelUrl() + "/" + PATH_LOGIN).method(HttpMethod.POST).header(HttpHeader.ACCEPT, "application/json").header(HttpHeader.CONTENT_TYPE, "application/json").content(new StringContentProvider(new Gson().toJson(loginForm)), "application/json");
        ContentResponse response = request.send();
        // Check HTTP status code
        int statusCode = response.getStatus();
        if (statusCode != HttpStatus.OK_200) {
            String reason = response.getReason();
            mCaller.httpStatusError(statusCode, reason, true);
            logger.debug("Communication with Z-Way server failed: {} {}", statusCode, reason);
        }
        String responseBody = response.getContentAsString();
        try {
            Gson gson = new Gson();
            // Response -> String -> Json -> extract data field
            JsonObject responseDataAsJson = gson.fromJson(responseBody, JsonObject.class).get("data").// extract data field
            getAsJsonObject();
            // extract SID field
            mZWaySessionId = responseDataAsJson.get("sid").getAsString();
            mCaller.getLoginResponse(mZWaySessionId);
            return mZWaySessionId;
        } catch (JsonParseException e) {
            mCaller.responseFormatError("Unexpected response format: " + e.getMessage(), false);
        }
    } catch (Exception e) {
        mCaller.apiError(e.getMessage(), false);
    } finally {
        stopHttpClient(httpClient);
    }
    mZWaySessionId = null;
    mCaller.authenticationError();
    return null;
}

[Buggy Hunk]
public String getLogin() {

[Patch]
public synchronized String getLogin() {