[Demonstration 1]

[Buggy Method]
public Message sendAudio(SendAudio sendAudio) throws TelegramApiException {
    String responseContent;
    try {
        String url = getBaseUrl() + SendAudio.PATH;
        HttpPost httppost = new HttpPost(url);
        httppost.setConfig(requestConfig);
        if (sendAudio.isNewAudio()) {
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addTextBody(SendAudio.CHATID_FIELD, sendAudio.getChatId());
            builder.addBinaryBody(SendAudio.AUDIO_FIELD, new java.io.File(sendAudio.getAudio()), ContentType.create("audio/mpeg"), sendAudio.getAudioName());
            if (sendAudio.getReplayMarkup() != null) {
                builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString());
            }
            if (sendAudio.getReplayToMessageId() != null) {
                builder.addTextBody(SendAudio.REPLYTOMESSAGEID_FIELD, sendAudio.getReplayToMessageId().toString());
            }
            if (sendAudio.getPerformer() != null) {
                builder.addTextBody(SendAudio.PERFOMER_FIELD, sendAudio.getPerformer());
            }
            if (sendAudio.getTitle() != null) {
                builder.addTextBody(SendAudio.TITLE_FIELD, sendAudio.getTitle());
            }
            if (sendAudio.getDuration() != null) {
                builder.addTextBody(SendAudio.DURATION_FIELD, sendAudio.getDuration().toString());
            }
            if (sendAudio.getDisableNotification() != null) {
                builder.addTextBody(SendAudio.DISABLENOTIFICATION_FIELD, sendAudio.getDisableNotification().toString());
            }
            HttpEntity multipart = builder.build();
            httppost.setEntity(multipart);
        } else {
            List<NameValuePair> nameValuePairs = new ArrayList<>();
            nameValuePairs.add(new BasicNameValuePair(SendAudio.CHATID_FIELD, sendAudio.getChatId()));
            nameValuePairs.add(new BasicNameValuePair(SendAudio.AUDIO_FIELD, sendAudio.getAudio()));
            if (sendAudio.getReplayMarkup() != null) {
                nameValuePairs.add(new BasicNameValuePair(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString()));
            }
            if (sendAudio.getReplayToMessageId() != null) {
                nameValuePairs.add(new BasicNameValuePair(SendAudio.REPLYTOMESSAGEID_FIELD, sendAudio.getReplayToMessageId().toString()));
            }
            if (sendAudio.getPerformer() != null) {
                nameValuePairs.add(new BasicNameValuePair(SendAudio.PERFOMER_FIELD, sendAudio.getPerformer()));
            }
            if (sendAudio.getTitle() != null) {
                nameValuePairs.add(new BasicNameValuePair(SendAudio.TITLE_FIELD, sendAudio.getTitle()));
            }
            if (sendAudio.getDisableNotification() != null) {
                nameValuePairs.add(new BasicNameValuePair(SendAudio.DISABLENOTIFICATION_FIELD, sendAudio.getDisableNotification().toString()));
            }
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, StandardCharsets.UTF_8));
        }
        try (CloseableHttpResponse response = httpclient.execute(httppost)) {
            HttpEntity ht = response.getEntity();
            BufferedHttpEntity buf = new BufferedHttpEntity(ht);
            responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
        }
    } catch (IOException e) {
        throw new TelegramApiException("Unable to send sticker", e);
    }
    JSONObject jsonObject = new JSONObject(responseContent);
    /* if we got not an "ok" with false, we have a response like that
         * 
         * {"description":"[Error]: Bad Request: chat not found","error_code":400,"ok":false}
         */
    if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) {
        throw new TelegramApiException("Error at sendAudio", jsonObject.getString(ERRORDESCRIPTIONFIELD), jsonObject.getInt(ERRORCODEFIELD));
    }
    // and if not, we can expect a "result" section. and out of this can a new Message object be built
    return new Message(jsonObject.getJSONObject(Constants.RESPONSEFIELDRESULT));
}

[Buggy Hunk]
builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString());

[Patch]
builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString(), ContentType.create("text/plain", StandardCharsets.UTF_8));

[Demonstration 2]

[Buggy Method]
public Message receive() throws IOException {
    try {
        return (Message) messageIn.readObject();
    } catch (ClassNotFoundException ex) {
        System.err.println("ClassNotFoundException when decoding an object from the socket stream.");
        assert false;
        return null;
    }
}

[Buggy Hunk]
public Message receive() throws IOException {

[Patch]
public Message receive() throws SocketTimeoutException, IOException {

[Demonstration 3]

[Buggy Method]
@Override
public List<T> saveSync(Iterable<T> entities) {
    Realm realm = null;
    try {
        realm = repositoryConfiguration.getRealmProvider().provideRealm();
        realm.beginTransaction();
        for (T entity : entities) {
            if (idGenerator != null && idSetter != null) {
                ID id = idGenerator.generateNextId();
                idSetter.setId(entity, id);
            }
        }
        List<T> newEntities = realm.copyToRealm(entities);
        realm.commitTransaction();
        return realm.copyFromRealm(newEntities);
    } finally {
        if (realm != null) {
            realm.close();
        }
    }
}

[Buggy Hunk]
List<T> newEntities = realm.copyToRealm(entities);

[Patch]
List<T> newEntities = realm.copyToRealmOrUpdate(entities);