[Demonstration 1]

[Buggy Method]
private byte[] GenerateFileSinkHeader() {
    byte[] header = new byte[HeaderLength];
    int currentByte = 0;
    int dataSize = (int) new File(fileSink.getLocation()).length();
    // ChunkID
    String id = "RIFF";
    byte[] idBytes = GetASCIIBytes(id, ByteOrder.BIG_ENDIAN);
    for (byte b : idBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // ChunkSize
    currentByte = 4;
    int chunkSize = 36 + dataSize;
    byte[] chunkSizeBytes = GetIntBytes(chunkSize, ByteOrder.LITTLE_ENDIAN);
    for (byte b : chunkSizeBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // Format
    currentByte = 8;
    String format = "WAVE";
    byte[] formatBytes = GetASCIIBytes(format, ByteOrder.BIG_ENDIAN);
    for (byte b : formatBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // Subchunk1ID
    currentByte = 12;
    String subchunk1ID = "fmt ";
    byte[] subchunk1IDBytes = GetASCIIBytes(subchunk1ID, ByteOrder.BIG_ENDIAN);
    for (byte b : subchunk1IDBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // Subchunk1Size
    currentByte = 16;
    int subChunk1Size = 16;
    byte[] subchunk1SizeBytes = GetIntBytes(subChunk1Size, ByteOrder.LITTLE_ENDIAN);
    for (byte b : subchunk1SizeBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // AudioFormat
    currentByte = 20;
    short audioFormat = 1;
    byte[] audioFormatBytes = GetShortBytes(audioFormat, ByteOrder.LITTLE_ENDIAN);
    for (byte b : audioFormatBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // NumChannels
    currentByte = 22;
    short numChannels = properties.NumChannels;
    byte[] numChannelsBytes = GetShortBytes(numChannels, ByteOrder.LITTLE_ENDIAN);
    for (byte b : numChannelsBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // SampleRate
    currentByte = 24;
    int sampleRate = properties.SampleRate;
    byte[] sampleRateBytes = GetIntBytes(sampleRate, ByteOrder.LITTLE_ENDIAN);
    for (byte b : sampleRateBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // ByteRate
    currentByte = 28;
    short bitsPerSample = properties.BitsPerSample;
    int byteRate = sampleRate * numChannels * (bitsPerSample / 8);
    byte[] byteRateBytes = GetIntBytes(byteRate, ByteOrder.LITTLE_ENDIAN);
    for (byte b : byteRateBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // BlockAlign
    currentByte = 32;
    short blockAlign = (short) (numChannels * (bitsPerSample / 8));
    byte[] blockAlignBytes = GetShortBytes(blockAlign, ByteOrder.LITTLE_ENDIAN);
    for (byte b : blockAlignBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // BitsPerSample
    currentByte = 34;
    byte[] bitsPerSampleBytes = GetShortBytes(bitsPerSample, ByteOrder.LITTLE_ENDIAN);
    for (byte b : bitsPerSampleBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // Subchunk2ID
    currentByte = 36;
    String subchunk2ID = "data";
    byte[] subchunk2IDBytes = GetASCIIBytes(subchunk2ID, ByteOrder.BIG_ENDIAN);
    for (byte b : subchunk2IDBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    // Subchunk2Size
    currentByte = 40;
    int subchunk2Size = dataSize;
    byte[] subchunk2SizeBytes = GetIntBytes(subchunk2Size, ByteOrder.LITTLE_ENDIAN);
    for (byte b : subchunk2SizeBytes) {
        header[currentByte] = b;
        currentByte++;
    }
    return header;
}

[Buggy Hunk]
byte[] header = new byte[HeaderLength];

[Patch]
byte[] header = new byte[44];

[Demonstration 2]

[Buggy Method]
public static Result service(String ownerName, String projectName, String service, boolean isAdvertise) throws IOException, UnsupportedOperationException, ServletException {
    if (!isSupportedService(service)) {
        return forbidden(String.format("Unsupported service: '%s'", service));
    }
    Project project = Project.findByOwnerAndProjectName(ownerName, projectName);
    if (project == null) {
        return notFound();
    }
    models.User user = UserApp.currentUser();
    if (!isAllowed(project, service)) {
        if (user.isAnonymous()) {
            return BasicAuthAction.unauthorized(response());
        } else {
            // If you want the Git client showing your custom message to
            // the user, the Content-Type should be exact "text/plain"
            // without any parameter. For more details, see the code at
            // https://github.com/git/git/commit/426e70d4a11ce3b4f70636d57c6a0ab16ae08a00#diff-eea0ad565ec5903a11b6023755d491cfR154
            response().setHeader("Content-Type", "text/plain");
            return forbidden(String.format("'%s' has no permission to '%s/%s'.", user.name, ownerName, projectName));
        }
    }
    if (isAdvertise) {
        return ok(RepositoryService.gitAdvertise(project, service, response()));
    } else {
        if (request().body().isMaxSizeExceeded()) {
            return status(REQUEST_ENTITY_TOO_LARGE);
        } else {
            user.visits(project);
            return ok(RepositoryService.gitRpc(project, service, request(), response()));
        }
    }
}

[Buggy Hunk]
user.name, ownerName, projectName));

[Patch]
user.loginId, ownerName, projectName));

[Demonstration 3]

[Buggy Method]
protected void handShake() throws IOException {
    if (ssl.getWantClientAuth()) {
        log.debug("No client cert sent for want");
    } else {
        ssl.setNeedClientAuth(true);
    }
    InputStream in = ssl.getInputStream();
    int oldTimeout = ssl.getSoTimeout();
    ssl.setSoTimeout(1000);
    byte[] b = new byte[0];
    listener.reset();
    ssl.startHandshake();
    // 60 * 1000 = example 1 minute time out
    int maxTries = 60;
    for (int i = 0; i < maxTries; i++) {
        if (log.isTraceEnabled())
            log.trace("Reading for try #" + i);
        try {
            int x = in.read(b);
        } catch (SSLException sslex) {
            log.info("SSL Error getting client Certs", sslex);
            throw sslex;
        } catch (IOException e) {
            // ignore - presumably the timeout
        }
        if (listener.completed) {
            break;
        }
    }
    // If legacy re-negotiation is disabled, socked could be closed here
    if (!ssl.isClosed()) {
        ssl.setSoTimeout(oldTimeout);
    }
    if (listener.completed == false) {
        throw new SocketException("SSL Cert handshake timeout");
    }
}

[Buggy Hunk]
byte[] b = new byte[0];

[Patch]
byte[] b = new byte[1];