[Demonstration 1]

[Buggy Method]
private static Object convertResultToArray(Class<?> elementType, List<?> result) {
    if (elementType.isPrimitive()) {
        if (boolean.class.equals(elementType)) {
            boolean[] array = new boolean[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Boolean) result.get(i);
            }
            return array;
        } else if (int.class.equals(elementType)) {
            int[] array = new int[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Integer) result.get(i);
            }
            return array;
        } else if (long.class.equals(elementType)) {
            long[] array = new long[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Long) result.get(i);
            }
            return array;
        } else if (short.class.equals(elementType)) {
            short[] array = new short[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Short) result.get(i);
            }
            return array;
        } else if (byte.class.equals(elementType)) {
            byte[] array = new byte[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Byte) result.get(i);
            }
            return array;
        } else if (float.class.equals(elementType)) {
            float[] array = new float[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Float) result.get(i);
            }
            return array;
        } else if (double.class.equals(elementType)) {
            double[] array = new double[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Double) result.get(i);
            }
            return array;
        } else if (char.class.equals(elementType)) {
            char[] array = new char[result.size()];
            for (int i = 0; i < result.size(); i++) {
                array[i] = (Character) result.get(i);
            }
            return array;
        }
    }
    return result.toArray((Object[]) Array.newInstance(elementType, result.size()));
}

[Buggy Hunk]
return result.toArray((Object[]) Array.newInstance(elementType, result.size()));

[Patch]
return result.toArray((Object[]) Array.newInstance(elementType, 0));

[Demonstration 2]

[Buggy Method]
private void testWithBackend(final ClearCLBackendInterface pClearCLBackendInterface) throws Exception {
    try (ClearCL lClearCL = new ClearCL(pClearCLBackendInterface)) {
        final int lNumberOfPlatforms = lClearCL.getNumberOfPlatforms();
        // System.out.println("lNumberOfPlatforms=" + lNumberOfPlatforms);
        for (int p = 0; p < lNumberOfPlatforms; p++) {
            final ClearCLPlatform lPlatform = lClearCL.getPlatform(p);
            // System.out.println(lPlatform.getInfoString());
            for (int d = 0; d < lPlatform.getNumberOfDevices(); d++) {
                final ClearCLDevice lClearClDevice = lPlatform.getDevice(d);
                /*System.out.println("\t" + d
                             + " -> \n"
                             + lClearClDevice.getInfoString());/**/
                final ClearCLContext lContext = lClearClDevice.createContext();
                final ClearCLProgram lProgram = lContext.createProgram(this.getClass(), "test.cl");
                lProgram.addDefine("CONSTANT", "1");
                // System.out.println(lProgram.getSourceCode());
                final BuildStatus lBuildStatus = lProgram.build();
                // System.out.println(lProgram.getBuildLog());
                System.out.println(lBuildStatus);
                assertEquals(lBuildStatus, BuildStatus.Success);
                // assertTrue(lProgram.getBuildLog().isEmpty());
                testBuffers(lContext, lProgram);
                testImages(lContext, lProgram);
            }
        }
    }
}

[Buggy Hunk]
final BuildStatus lBuildStatus = lProgram.build();

[Patch]
final BuildStatus lBuildStatus = lProgram.buildAndLog();

[Demonstration 3]

[Buggy Method]
private void redrawHazards() {
    if (hazardViews_ == null) {
        hazardViews_ = new TextSwitcher[NUM_HAZARDS];
        hazardViews_[0] = (TextSwitcher) findViewById(R.id.hazard1);
        hazardViews_[1] = (TextSwitcher) findViewById(R.id.hazard2);
        hazardViews_[2] = (TextSwitcher) findViewById(R.id.hazard3);
        hazardViews_[3] = (TextSwitcher) findViewById(R.id.hazard4);
        hazardViews_[4] = (TextSwitcher) findViewById(R.id.hazard5);
        for (TextSwitcher ts : hazardViews_) initSwitcher(ts);
    }
    // Get SQL data
    Hazard[] newHazards = getHazardRankings(NUM_HAZARDS);
    for (int i = 0; i < NUM_HAZARDS; i++) {
        if (newHazards == null)
            hazardViews_[i].setText("Unavailable");
        else if (newHazards[i] == null || i >= newHazards.length)
            hazardViews_[i].setText("");
        else if (hazards_[i] == null || !hazards_[i].equals(newHazards[i])) {
            hazardViews_[i].setText(newHazards[i].getText());
        }
    }
    if (newHazards == null)
        hazards_ = new Hazard[NUM_HAZARDS];
    else
        hazards_ = Arrays.copyOf(newHazards, NUM_HAZARDS);
}

[Buggy Hunk]
hazardViews_[i].setText(newHazards[i].getText());

[Patch]
hazardViews_[i].setText("[+] " + newHazards[i].getText());