[Demonstration 1]

[Buggy Method]
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> results) throws Exception {
    if (discardingTooLongFrame) {
        bytesToDiscard = discard(buffer, bytesToDiscard);
        // If we have discarded everything, throw the exception
        if (bytesToDiscard <= 0)
            fail();
        return;
    }
    // Wait until we have read at least the short header
    if (buffer.readableBytes() < Header.LEGACY_LENGTH)
        return;
    int idx = buffer.readerIndex();
    int firstByte = buffer.getByte(idx++);
    Message.Direction direction = Message.Direction.extractFromVersion(firstByte);
    int version = firstByte & 0x7F;
    if (version > Server.CURRENT_VERSION)
        throw new ProtocolException("Invalid or unsupported protocol version: " + version);
    // Wait until we have the complete V3+ header
    if (version >= Server.VERSION_3 && buffer.readableBytes() < Header.MODERN_LENGTH)
        return;
    int flags = buffer.getByte(idx++);
    int streamId, headerLength;
    if (version >= Server.VERSION_3) {
        streamId = buffer.getShort(idx);
        idx += 2;
        headerLength = Header.MODERN_LENGTH;
    } else {
        streamId = buffer.getByte(idx);
        idx++;
        headerLength = Header.LEGACY_LENGTH;
    }
    // This throws a protocol exceptions if the opcode is unknown
    Message.Type type;
    try {
        type = Message.Type.fromOpcode(buffer.getByte(idx++), direction);
    } catch (ProtocolException e) {
        throw ErrorMessage.wrap(e, streamId);
    }
    long bodyLength = buffer.getUnsignedInt(idx);
    idx += Header.BODY_LENGTH_SIZE;
    if (bodyLength < 0) {
        buffer.skipBytes(headerLength);
        throw ErrorMessage.wrap(new ProtocolException("Invalid frame body length: " + bodyLength), streamId);
    }
    long frameLength = bodyLength + headerLength;
    if (frameLength > MAX_FRAME_LENGTH) {
        // Enter the discard mode and discard everything received so far.
        discardingTooLongFrame = true;
        tooLongStreamId = streamId;
        tooLongFrameLength = frameLength;
        bytesToDiscard = discard(buffer, frameLength);
        if (bytesToDiscard <= 0)
            fail();
        return;
    }
    if (buffer.readableBytes() < frameLength)
        return;
    // extract body
    ByteBuf body = buffer.slice(idx, (int) bodyLength);
    body.retain();
    idx += bodyLength;
    buffer.readerIndex(idx);
    Connection connection = ctx.channel().attr(Connection.attributeKey).get();
    if (connection == null) {
        // First message seen on this channel, attach the connection object
        connection = factory.newConnection(ctx.channel(), version);
        ctx.channel().attr(Connection.attributeKey).set(connection);
    } else if (connection.getVersion() != version) {
        throw ErrorMessage.wrap(new ProtocolException(String.format("Invalid message version. Got %d but previous messages on this connection had version %d", version, connection.getVersion())), streamId);
    }
    results.add(new Frame(new Header(version, flags, streamId, type), body));
}

[Buggy Hunk]
int version = firstByte & 0x7F;

[Patch]
int version = firstByte & PROTOCOL_VERSION_MASK;

[Demonstration 2]

[Buggy Method]
private static void listSalientFiles(String workingDir, String project, int compressionRatio, int backoffTopic, File outFolder, String samplerLoc, Boolean ignoreTestFiles) {
    final Settings set = new Settings();
    // Main code folder settings
    set.backoffTopicID = backoffTopic;
    set.curProj = project;
    set.compressionRatio = compressionRatio;
    // Load Topic Model
    System.out.println("Deserializing the model...");
    final GibbsSampler sampler = GibbsSampler.readCorpus(samplerLoc + "TopicSum/Source/SamplerState.ser");
    // Get all java files in source folder
    final List<File> files = (List<File>) FileUtils.listFiles(new File(workingDir + project + "/"), new String[] { "java" }, true);
    int count = 0;
    List<FileScore> fileScores = new ArrayList<ListSalientFiles.FileScore>();
    for (final File file : files) {
        // Ignore empty files
        if (file.length() == 0)
            continue;
        if (count % 50 == 0)
            System.out.println("At file " + count + " of " + files.size());
        count++;
        List<String> lines = CodeUtils.getTokenList(file, set);
        List<Integer> lineNumbers = new ArrayList<Integer>();
        for (int i = 0; i < lines.size(); i++) {
            lineNumbers.add(i);
        }
        final String curFile = StringUtils.removeStart(file.getPath(), workingDir + project + "/");
        Double klScore = -1 * sampler.getKLDiv("KLDivProj", set.backoffTopicID, set.curProj, curFile, lineNumbers);
        fileScores.add(new FileScore(file.getPath(), klScore));
    }
    if (ignoreTestFiles) {
        Iterator<FileScore> iter = fileScores.iterator();
        while (iter.hasNext()) {
            String filePath = iter.next().filePath;
            if (filePath.contains("test") || filePath.contains("Test")) {
                iter.remove();
            }
        }
    }
    int desiredNumberOfFiles = fileScores.size() * compressionRatio / 100;
    System.out.println("===============================================================");
    System.out.println("Listing salient files for project: " + project);
    System.out.println("Total files: " + fileScores.size() + "\t" + " Reducing to: " + desiredNumberOfFiles);
    System.out.println("===============================================================");
    Collections.sort(fileScores);
    int i = 0;
    for (i = 0; i < desiredNumberOfFiles; i++) {
        System.out.println(fileScores.get(i).score + "\t" + fileScores.get(i).filePath);
    }
    System.out.println("\n \n===============================================================");
    System.out.println("Next 20 important files :");
    System.out.println("===============================================================");
    for (int j = 0; i < fileScores.size() && j < 20; j++, i++) {
        System.out.println(fileScores.get(i).score + "\t" + fileScores.get(i).filePath);
    }
}

[Buggy Hunk]
final String curFile = StringUtils.removeStart(file.getPath(), workingDir + project + "/");

[Patch]
final String curFile = CodeUtils.getRelativePath(file, project);

[Demonstration 3]

[Buggy Method]
@Override
public void reset(@NotNull Path path) throws IOException {
    Map<String, VcsBlobLink> committed = getCommittedFiles();
    if (!committed.containsKey(path.toString())) {
        throw new IOException("no such committed file");
    }
    String blob_name = committed.get(path.toString()).md5_hash;
    Path blob_path = Paths.get(blobs_dir_path.toString(), blob_name);
    Files.copy(blob_path, path);
}

[Buggy Hunk]
Files.copy(blob_path, path);

[Patch]
Files.copy(blob_path, path, REPLACE_EXISTING);