[Demonstration 1]

[Buggy Method]
public static void writeModelToFile(final String fileName, final Model model, final String format) {
    final File file = new File(fileName);
    try {
        final FileOutputStream fos = new FileOutputStream(file);
        System.out.println(String.join("", "[Info] Writing data to RDF file, ", fileName, " using format '", format, "'"));
        try {
            RDFDataMgr.write(fos, model, RDFFormat.NTRIPLES);
            fos.close();
        } catch (IOException ioExc) {
            System.err.println("[Error] while closing file stream.");
        }
    } catch (FileNotFoundException exc) {
        System.err.println(String.join("", "[Error] Could not open output file ", fileName));
    }
}

[Buggy Hunk]
RDFDataMgr.write(fos, model, RDFFormat.NTRIPLES);

[Patch]
RDFDataMgr.write(fos, model, RDFService.RDF_FORMAT_MAP.get(format));

[Demonstration 2]

[Buggy Method]
public synchronized void writeLog(String content) {
    try {
        FileWriter fw = new FileWriter("logs/" + filename + id, true);
        fw.write(content + "\n");
        fw.close();
    } catch (IOException e) {
    }
}

[Buggy Hunk]
FileWriter fw = new FileWriter("logs/"+filename+id,true);

[Patch]
FileWriter fw = new FileWriter("logs/"+filename+server_id,true);

[Demonstration 3]

[Buggy Method]
public static boolean doAction(String action, PartnerConnection partnerConnection, DatasetUtilParams params) {
    if (action == null) {
        printUsage();
        System.out.println("\nERROR: Invalid action {" + action + "}");
        return false;
    }
    if (params.inputFile != null) {
        File tempFile = validateInputFile(params.inputFile, action);
        if (tempFile == null) {
            System.out.println("Inputfile {" + params.inputFile + "} is not valid");
            return false;
        }
    }
    if (params.dataset != null && !params.dataset.isEmpty()) {
        if (params.datasetLabel == null)
            params.datasetLabel = params.dataset;
        String santizedDatasetName = ExternalFileSchema.createDevName(params.dataset, "Dataset", 1, false);
        if (!params.dataset.equals(santizedDatasetName)) {
            System.out.println("\n Warning: dataset name can only contain alpha-numeric or '_', must start with alpha, and cannot end in '__c'");
            System.out.println("\n changing dataset name to: {" + santizedDatasetName + "}");
            params.dataset = santizedDatasetName;
        }
    }
    Charset fileCharset = null;
    try {
        if (params.fileEncoding != null && !params.fileEncoding.trim().isEmpty())
            fileCharset = Charset.forName(params.fileEncoding);
        else
            fileCharset = Charset.forName("UTF-8");
    } catch (Throwable e) {
        e.printStackTrace();
        System.out.println("\nERROR: Invalid fileEncoding {" + params.fileEncoding + "}");
        return false;
    }
    if (action.equalsIgnoreCase("load")) {
        if (params.inputFile == null || params.inputFile.isEmpty()) {
            System.out.println("\nERROR: inputFile must be specified");
            return false;
        }
        if (params.dataset == null || params.dataset.isEmpty()) {
            System.out.println("\nERROR: dataset name must be specified");
            return false;
        }
        Session session = null;
        try {
            String orgId = null;
            orgId = partnerConnection.getUserInfo().getOrganizationId();
            session = Session.getCurrentSession(orgId, params.dataset);
            //					session = new Session(orgId,params.dataset);
            //			        ThreadContext threadContext = ThreadContext.get();
            //			        threadContext.setSession(session);
            session.start();
            try {
                boolean status = DatasetLoader.uploadDataset(params.inputFile, params.uploadFormat, params.codingErrorAction, fileCharset, params.dataset, params.app, params.datasetLabel, params.Operation, params.useBulkAPI, partnerConnection, System.out);
                if (status)
                    session.end();
                else
                    session.fail("Check sessionLog for details");
                return status;
            } catch (DatasetLoaderException e) {
                session.fail(e.getMessage());
                return false;
            }
        } catch (Exception e) {
            System.out.println();
            e.printStackTrace(System.out);
            if (session != null)
                session.fail(e.getLocalizedMessage());
            return false;
        }
    } else if (action.equalsIgnoreCase("detectEncoding")) {
        if (params.inputFile == null) {
            System.out.println("\nERROR: inputFile must be specified");
            return false;
        }
        try {
            CharsetChecker.detectCharset(new File(params.inputFile));
        } catch (Exception e) {
            e.printStackTrace(System.out);
            return false;
        }
    } else if (action.equalsIgnoreCase("uploadxmd")) {
        if (params.inputFile == null) {
            System.out.println("\nERROR: inputFile must be specified");
            return false;
        }
        if (params.dataset == null) {
            System.out.println("\nERROR: dataset must be specified");
            return false;
        }
        try {
            XmdUploader.uploadXmd(params.inputFile, params.dataset, partnerConnection);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            return false;
        }
    } else if (action.equalsIgnoreCase("downloadxmd")) {
        if (params.dataset == null) {
            System.out.println("\nERROR: dataset alias must be specified");
            return false;
        }
        try {
            DatasetDownloader.downloadEM(params.dataset, partnerConnection);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            return false;
        }
    } else if (action.equalsIgnoreCase("defineAugmentFlow")) {
        try {
            DatasetAugmenter.augmentEM(partnerConnection);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            return false;
        }
    } else if (action.equalsIgnoreCase("defineExtractFlow")) {
        if (params.rootObject == null) {
            System.out.println("\nERROR: rootObject must be specified");
            return false;
        }
        try {
            SfdcExtracter.extract(params.rootObject, params.dataset, partnerConnection, params.rowLimit);
        } catch (Exception e) {
            e.printStackTrace(System.out);
            return false;
        }
    } else if (action.equalsIgnoreCase("downloadErrorFile")) {
        if (params.dataset == null) {
            System.out.println("\nERROR: dataset alias must be specified");
            return false;
        }
        try {
            DataFlowMonitorUtil.getJobsAndErrorFiles(partnerConnection, params.dataset);
        } catch (Exception e) {
            System.out.println();
            e.printStackTrace(System.out);
            return false;
        }
    } else {
        printUsage();
        System.out.println("\nERROR: Invalid action {" + action + "}");
        return false;
    }
    return true;
}

[Buggy Hunk]
session = Session.getCurrentSession(orgId, params.dataset);

[Patch]
session = Session.getCurrentSession(orgId, params.dataset, true);