[Demonstration 1]

[Buggy Method]
private void setup() {
    programPushed = false;
    Map<String, String> envVars = System.getenv();
    androidProductOut = checkForEnvVar(envVars, "ANDROID_PRODUCT_OUT");
    androidHostOut = checkForEnvVar(envVars, "ANDROID_HOST_OUT");
    if (Options.executeOnHost) {
        File coreImage = new File(getHostCoreImagePath());
        if (!coreImage.exists()) {
            Log.errorAndQuit("Host core image not found at " + coreImage.getPath() + ". Did you forget to build it?");
        }
    }
    if (!isHost) {
        // Create temporary consumers for the initial test.
        StreamConsumer outputConsumer = new StreamConsumer();
        outputConsumer.start();
        StreamConsumer errorConsumer = new StreamConsumer();
        errorConsumer.start();
        // Check for ADB.
        try {
            ProcessBuilder pb = new ProcessBuilder();
            pb.command("adb", "devices");
            Process process = pb.start();
            int exitValue = process.waitFor();
            if (exitValue != 0) {
                Log.errorAndQuit("Problem executing ADB - is it in your $PATH?");
            }
        } catch (IOException e) {
            Log.errorAndQuit("IOException when executing ADB, is it working?");
        } catch (InterruptedException e) {
            Log.errorAndQuit("InterruptedException when executing ADB, is it working?");
        }
        // Check we can run something on ADB.
        ExecutionResult result = executeCommand("true", true, outputConsumer, errorConsumer);
        if (result.getFlattenedAll().contains("device not found")) {
            Log.errorAndQuit("Couldn't connect to specified ADB device: " + deviceName);
        }
        outputConsumer.shutdown();
        errorConsumer.shutdown();
    } else {
        androidData = checkForEnvVar(envVars, "ANDROID_DATA");
    }
}

[Buggy Hunk]
File coreImage = new File(getHostCoreImagePath());

[Patch]
File coreImage = new File(getHostCoreImagePath(true));

[Demonstration 2]

[Buggy Method]
public void loadDocument(String filePath) {
    try {
        File file = new File("language.xml");
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        document = dBuilder.parse(file);
        document.getDocumentElement().normalize();
    } catch (Exception e) {
    }
}

[Buggy Hunk]
File file =  new File("language.xml");

[Patch]
File file =  new File(filePath);

[Demonstration 3]

[Buggy Method]
@Test
public void testGradeWithNullCheck() throws IOException {
    File testSrc = new File("/home/dominik/TestSrc.java");
    BufferedWriter testSrcOut = new BufferedWriter(new FileWriter(testSrc));
    testSrcOut.write("public class TestSrc\n" + "{\n" + "\tpublic static void main(String... args)\n" + "\t{\n" + "\t\tfor (int i = 1; i < 11; i++)\n" + "\t\t{\n" + "\t\t\tSystem.out.println(i);\n" + "\t\t}\n" + "\t}\n" + "}");
    testSrcOut.close();
    File testOut = File.createTempFile("TestOutput", "txt");
    testSrc.deleteOnExit();
    BufferedWriter testOutOut = new BufferedWriter(new FileWriter(testOut));
    testOutOut.write("1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "6\n" + "7\n" + "8\n" + "9\n" + "10\n");
    testOutOut.close();
    HashMap<String, Integer> testSearchStrings = new HashMap<>();
    testSearchStrings.put("for *\\(.*\\)", 1);
    testSearchStrings.put("while *\\(.*\\)", 2);
    Either<Integer, String> result = Grader.grade(testSrc, null, testOut, false, false, testSearchStrings);
    assertEquals(98, result.getLeft().intValue());
    assertEquals(null, result.getRight());
}

[Buggy Hunk]
public void testGradeWithNullCheck() throws IOException

[Patch]
public void testGradeWithNullCheck() throws Exception