[Demonstration 1]

[Buggy Method]
protected void downloadImpl() {
    FTPClient ftpClient = null;
    FileOutputStream fileOutputStream = null;
    InputStream input = null;
    boolean forceResume = false;
    while (mState == State.Started || mState == State.Downloading) {
        try {
            File f = getLocalFile();
            mConfig.localFile = f;
            long alreadyDownloaded = onPreInit(f, forceResume);
            forceResume = false;
            //state can be set in getLocalFile when pieceLen and fileSize are same
            if (mState == State.Downloaded || mState == State.Finished) {
                mDownloaded = mConfig.currentPieceLength;
                break;
            }
            //connect
            setFtpState(State.Connecting);
            ftpClient = FTPFactory.openFtpClient(mConfig);
            setFtpState(State.Connected);
            //init start values
            final long startOffset = ((long) mConfig.part * (long) mConfig.globalPieceLength) + alreadyDownloaded;
            ftpClient.setRestartOffset(startOffset);
            //create streams
            input = ftpClient.retrieveFileStream(mConfig.remoteFullPath);
            if (input == null || ftpClient.getReplyCode() >= 300) {
                throw new FatalFTPException(TextUtils.getFtpCodeName(ftpClient.getReplyCode()) + "\n" + ftpClient.getReplyString());
            }
            fileOutputStream = new FileOutputStream(f, startOffset > 0);
            setFtpState(State.Downloading);
            //download
            byte[] buffer = new byte[mConfig.bufferSize];
            int len = 0;
            mDownloaded = alreadyDownloaded;
            long downloadedInSec = 0;
            long lastNotify = System.currentTimeMillis();
            //region datacopy
            while ((len = input.read(buffer)) != -1) {
                long now = System.currentTimeMillis();
                //call notification methods
                if ((now - lastNotify) > NOTIFY) {
                    //count avg speed in defined time for 1s
                    int v = (int) (downloadedInSec / (float) NOTIFY) * 1000;
                    onDownloadProgress(mDownloaded, v);
                    mSpeed = v;
                    downloadedInSec = 0;
                    lastNotify = now;
                }
                final int subLen = (int) (mConfig.currentPieceLength - mDownloaded);
                final int realLenToWrite = Math.min(len, subLen);
                fileOutputStream.write(buffer, 0, realLenToWrite);
                //save values for notification
                mDownloaded += realLenToWrite;
                downloadedInSec += realLenToWrite;
                //stop, we are complete
                if (mDownloaded == mConfig.currentPieceLength) {
                    break;
                }
                //wait if user paused downloading
                if (mState == State.Paused) {
                    synchronized (mLock) {
                        //set again and notify about state change
                        setFtpState(State.Paused);
                        mLock.wait();
                        //here you can be only in Downloading state
                        setFtpState(State.Downloading);
                        //set force resume if there is any trouble
                        forceResume = true;
                    }
                }
            }
            //endregion datacopy
            //close and finish
            ftpClient.disconnect();
            if (mConfig.currentPieceLength == mDownloaded) {
                setFtpState(mConfig.parts == 1 ? State.Finished : State.Downloaded);
            }
            //otherwise just restart process and again
        } catch (FatalFTPException ffe) {
            mFatalErrorCounter++;
            mException = ffe;
            ffe.printStackTrace();
            onFatalError(ffe);
            if (mFatalErrorCounter >= FATAL_ERROR_TO_STOP) {
                setFtpState(State.FatalError);
                return;
            } else {
                setFtpState(State.WaitingForRetry);
                //wait 10s and try again
                try {
                    Thread.sleep(DEFAULT_WAIT);
                } catch (InterruptedException e1) {
                    /* ignore wake */
                }
            }
        } catch (IOException e) {
            onError(e);
            setFtpState(State.WaitingForRetry);
            //wait 10s and try again
            try {
                Thread.sleep(DEFAULT_WAIT);
            } catch (InterruptedException e1) {
                /* ignore wake */
            }
        } catch (Throwable t) {
            mException = t;
            onFatalError(new FatalFTPException(t));
            setFtpState(State.Error);
            synchronized (mLock) {
                try {
                    mLock.wait();
                } catch (InterruptedException e) {
                    /* ignore wake */
                }
            }
        } finally {
            //region close and release everything
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (Exception e) {
                    /**/
                }
            }
            if (input != null) {
                try {
                    input.close();
                } catch (Exception e) {
                    /**/
                }
            }
            if (ftpClient != null) {
                try {
                    ftpClient.disconnect();
                } catch (Exception e) {
                    /**/
                }
            }
            //endregion
        }
    }
}

[Buggy Hunk]
final long startOffset = ((long)mConfig.part * (long)mConfig.globalPieceLength) + alreadyDownloaded;

[Patch]
final long startOffset = ((long)mConfig.part * mConfig.globalPieceLength) + alreadyDownloaded;

[Demonstration 2]

[Buggy Method]
public static void decrypt(String key, File input, File output) throws NoSuchAlgorithmException, DecoderException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidParameterSpecException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, IOException {
    FileInputStream fin = new FileInputStream(input);
    byte[] iv = new byte[KEYLEN_BITS / 8];
    fin.read(iv);
    SecretKeySpec secret = new SecretKeySpec(Hex.decodeHex(key.toCharArray()), "AES");
    Cipher cipher = Cipher.getInstance(AES);
    cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv));
    FileOutputStream fout = new FileOutputStream(output);
    int nread = 0;
    byte[] inbuf = new byte[MAX_FILE_BUF];
    CipherInputStream cin = new CipherInputStream(fin, cipher);
    while ((nread = cin.read(inbuf)) > 0) {
        byte[] trimbuf = new byte[nread];
        System.arraycopy(inbuf, 0, trimbuf, 0, nread);
        fout.write(trimbuf);
    }
    fout.flush();
    cin.close();
    fin.close();
    fout.close();
}

[Buggy Hunk]
byte[] iv = new byte[KEYLEN_BITS / 8];

[Patch]
byte[] iv = new byte[16];

[Demonstration 3]

[Buggy Method]
protected void onClickUser(View view) {
    // Start the native auth flow.
    Intent intent = FoursquareOAuth.getConnectIntent(MainActivity.this, CLIENT_ID);
    // If the device does not have the Foursquare app installed, we'd
    // get an intent back that would open the Play Store for download.
    // Otherwise we start the auth flow.
    if (FoursquareOAuth.isPlayStoreIntent(intent)) {
        toastMessage(MainActivity.this, getString(R.string.app_not_installed_message));
        startActivity(intent);
    } else {
        startActivityForResult(intent, REQUEST_CODE_FSQ_CONNECT);
    }
}

[Buggy Hunk]
protected void onClickUser(View view){

[Patch]
public void onClickUser(View view){