[Demonstration 1]

[Buggy Method]
protected synchronized void endPlayerTurn() {
    notifyDisableAllCardsListeners();
    this.roundCounter++;
    while (players[getCurrentPlayerTurn()].getisQuiteFromGame() == true) {
        this.roundCounter++;
    }
    if ((deck.getDeckSize() == 0 && board.getNumOfUnrevealedCard() == 0)) {
        //|| (this.isGoldFishMode && board.getNumberOfLegalWords(card->card!=null) ==0 || gameOver)){
        gameOver = true;
        isGameStarted = false;
        if (players[0].getScore() > players[1].getScore()) {
            winnerPlayer = 0;
        } else if (players[0].getScore() == players[1].getScore()) {
            winnerPlayer = -1;
        } else {
            winnerPlayer = 1;
        }
        notifyGameOverListeners(getCurrentPlayerTurn());
    } else {
        notifyStartPlayerTurn();
        createNewMove();
        if (isGoldFishMode) {
            board.ChangeAllCardsToUnrevealed();
        }
        players[getCurrentPlayerTurn()].setRetriesNumber(retriesNumber);
        if (players[getCurrentPlayerTurn()] instanceof ComputerPlayer) {
            ComputerPlayerPlayTurnTask task = new ComputerPlayerPlayTurnTask((ComputerPlayer) players[getCurrentPlayerTurn()]);
            new Thread(task).start();
        }
    }
}

[Buggy Hunk]
if ((deck.getDeckSize() == 0 && board.getNumOfUnrevealedCard() ==0)){

[Patch]
if ((deck.getDeckSize() == 0 && board.getNumOfUnrevealedCard() ==0) || gameOver){

[Demonstration 2]

[Buggy Method]
@Override
public SoundBuffer readAll() {
    // Check to make sure there is an audio format:
    if (myAudioFormat == null) {
        errorMessage("Audio Format null in method 'readAll'");
        return null;
    }
    // Array to contain the audio data:
    byte[] fullBuffer = null;
    // Determine how much data will be read in:
    int fileSize = myAudioFormat.getChannels() * (int) myAudioInputStream.getFrameLength() * myAudioFormat.getSampleSizeInBits() / 8;
    if (fileSize > 0) {
        // Allocate memory for the audio data:
        fullBuffer = new byte[myAudioFormat.getChannels() * (int) myAudioInputStream.getFrameLength() * myAudioFormat.getSampleSizeInBits() / 8];
        int read = 0, total = 0;
        try {
            // Read until the end of the stream is reached:
            while ((read = myAudioInputStream.read(fullBuffer, total, fullBuffer.length - total)) != -1 && total < fullBuffer.length) {
                total += read;
            }
        } catch (IOException e) {
            errorMessage("Exception thrown while reading from the " + "AudioInputStream (location #1).");
            printStackTrace(e);
            return null;
        }
    } else {
        // Total file size unknown.
        // Variables used when reading from the audio input stream:
        int totalBytes = 0, bytesRead = 0, cnt = 0;
        byte[] smallBuffer = null;
        // Allocate memory for a chunk of data:
        smallBuffer = new byte[SoundSystemConfig.getFileChunkSize()];
        // Read until end of file or maximum file size is reached:
        while ((!endOfStream(GET, XXX)) && (totalBytes < SoundSystemConfig.getMaxFileSize())) {
            bytesRead = 0;
            cnt = 0;
            try {
                // Read until small buffer is filled or end of file reached:
                while (bytesRead < smallBuffer.length) {
                    myAudioInputStream.execute();
                    if ((cnt = myAudioInputStream.read(smallBuffer, bytesRead, smallBuffer.length - bytesRead)) <= 0) {
                        endOfStream(SET, true);
                        break;
                    }
                    bytesRead += cnt;
                }
            } catch (IOException e) {
                errorMessage("Exception thrown while reading from the " + "AudioInputStream (location #2).");
                printStackTrace(e);
                return null;
            }
            // Reverse byte order if necessary:
            // if( reverseBytes )
            // reverseBytes( smallBuffer, 0, bytesRead );
            // Keep track of the total number of bytes read:
            totalBytes += bytesRead;
            // Append the small buffer to the full buffer:
            fullBuffer = appendByteArrays(fullBuffer, smallBuffer, bytesRead);
        }
    }
    // Insert the converted data into a ByteBuffer
    // byte[] data = convertAudioBytes( fullBuffer,
    // myAudioFormat.getSampleSizeInBits() == 16 );
    // Wrap the data into an SoundBuffer:
    SoundBuffer soundBuffer = new SoundBuffer(fullBuffer, myAudioFormat);
    // Close the audio input stream
    try {
        myAudioInputStream.close();
    } catch (IOException e) {
    }
    // Return the result:
    return soundBuffer;
}

[Buggy Hunk]
smallBuffer.length - bytesRead)) <= 0)

[Patch]
smallBuffer.length - bytesRead)) < 0)

[Demonstration 3]

[Buggy Method]
public static String getHash(InputStream input, HashingAlgorithm algorithm) {
    byte[] buffer = new byte[1024];
    try {
        MessageDigest algo = MessageDigest.getInstance(algorithm.getName());
        int readBytes;
        do {
            readBytes = input.read(buffer);
            algo.update(buffer);
        } while (readBytes == buffer.length);
        byte[] messageDigest = algo.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            String token = Integer.toHexString(0xFF & messageDigest[i]);
            // Make sure each is exactly 2 chars long
            if (token.length() < 2) {
                hexString.append("0");
            }
            hexString.append(token);
        }
        return hexString.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

[Buggy Hunk]
algo.update(buffer);

[Patch]
algo.update(buffer, 0, readBytes);